influxdata / influxdb

Scalable datastore for metrics, events, and real-time analytics
https://influxdata.com
Apache License 2.0
28.56k stars 3.53k forks source link

`/api/v2/templates/apply` allows only one object in `remotes` #23607

Open jstirnaman opened 2 years ago

jstirnaman commented 2 years ago

/api/v2/templates/apply returns duplicate name validation errors and unprocessable entity status when I pass multiple objects in the remotes array.

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

  1. In the request body, pass an array of {"url": "TEMPLATE_URL"} objects with theremotes` parameter--for example:

    curl -v --request POST \
    "${INFLUX_URL}/api/v2/templates/apply" \
    --header "Authorization: Token ${INFLUX_ALL_ACCESS_TOKEN}" \
    --data @- << EOF
      {
        "orgID": "$INFLUX_ORG_ID",
        "dryRun": true,
        "remotes": [
          {
            "url": "https://raw.githubusercontent.com/influxdata/community-templates/master/linux_system/linux_system.yml"
          },
          {
            "url": "https://raw.githubusercontent.com/influxdata/community-templates/master/aws_lambda/lambda.yml"
          }
        ]
      }
    EOF

Expected behavior: Expect both templates to be applied, as implied by the spec: https://docs.influxdata.com/influxdb/v2.3/api/#operation/ApplyTemplate.

Actual behavior: Responds with HTTP 422 status and the following errors:

        "errors": [
                {
                        "kind": "Variable",
                        "fields": [
                                "root",
                                "spec",
                                "name"
                        ],
                        "idxs": [
                                17,
                                null,
                                null
                        ],
                        "reason": "duplicate name: lucid-kepler-8bf001"
                }
        ],
        "code": "unprocessable entity",
        "message": "unprocessable entity"

If I pass each URL in a separate request - only one object in remotes: [], then the templates apply successfully.

Environment info:

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.
jeffreyssmith2nd commented 2 years ago

Something to note, Cloud2 exhibits the same behavior as OSS in this case