influxdata / influxdata/influxdb

api/v2/templates/apply isn't clear that template and templates are mutually exclusive

Open
#23,605 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

Steps to reproduce:
List the minimal actions needed to reproduce the behavior.

  1. Pass the following in a request body to `/api/v2/templates/apply:
    • template property with a Template object.
    • templates property with an array of Template objects.
  2. In Template objects for each property, include a resource with the same kind--for example, two resources with "kind": "Label":
  curl -v "${INFLUX_URL}/api/v2/templates/apply" \
    --header "Authorization: Token ${INFLUX_ALL_ACCESS_TOKEN}" \
    --data @- << EOF
    { "orgID": "$INFLUX_ORG_ID",
      "dryRun": true,
      "templates": [
        { "contents": [{
            "apiVersion": "influxdata.com/v2alpha1",
            "kind": "Label",
            "metadata": {
              "name": "unruffled-benz-001"
            },
            "spec": {
              "color": "#326BBA",
              "name": "inputs.cpu"
            }
          }]
        }
      ],
      "template": {
        "contents": [
          {
            "apiVersion": "influxdata.com/v2alpha1",
            "kind": "Bucket",
            "metadata": {
              "name": "heuristic-sinoussi-004"
            },
            "spec": {
              "name": "docker",
              "retentionRules": [
                {
                  "everySeconds": 604800,
                  "type": "expire"
                }
              ]
            }
          },
          {
            "apiVersion": "influxdata.com/v2alpha1",
            "kind": "Label",
            "metadata": {
              "name": "unruffled-benz-004"
            },
            "spec": {
              "color": "#326BBA",
              "name": "inputs.cpu"
            }
          }
        ]
      }  
    }
EOF

Expected behavior:
I expect the error reason to report that template and templates aren't allowed together in the request.

Actual behavior:
Instead, the error reason reports a duplicate name for one of the resources:

       "errors": [
                {
                        "kind": "Label",
                        "fields": [
                                "root",
                                "spec",
                                "name"
                        ],
                        "idxs": [
                                2,
                                null,
                                null
                        ],
                        "reason": "duplicate name: unruffled-benz-004"
                }
        ],
        "code": "unprocessable entity",
        "message": "unprocessable entity"

Environment info:

  • System info: Darwin 21.6.0 x86_64
  • InfluxDB version: InfluxDB 2.3.0 (git: 090f681737) build_date: 2022-06-16T18:48:06Z

Config:
Copy any non-default config values here or attach the full config as a gist or file.

Logs:
Include snippet of errors in log.

Performance:
Generate profiles with the following commands for bugs related to performance, locking, out of memory (OOM), etc.

# Commands should be run when the bug is actively happening.
# Note: This command will run for ~30 seconds.
curl -o profiles.tar.gz "http://localhost:8086/debug/pprof/all?cpu=30s"
iostat -xd 1 30 > iostat.txt
# Attach the `profiles.tar.gz` and `iostat.txt` output files.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the /api/v2/templates/apply request handling and validation path, using the provided curl body to reproduce the behavior. Verify that supplying both template and templates produces an error stating they are mutually exclusive, rather than a duplicate-resource error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.