elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.71k stars 8.12k forks source link

[Fleet] agent_download_sources API resets "is_default" value if it is run twice #183318

Open mrodm opened 4 months ago

mrodm commented 4 months ago

Kibana version: 8.13.0 and 8.14.0-SNAPSHOT

Describe the bug: If the POST agent_download_sources query is executed twice setting with the same body (a new default source with is_default key). Second run of the command fails with a 409 error (expected), but updates the is_default key to be false.

Steps to reproduce:

  1. Create a new source using agent_download_sources API:
    • Dev Tools query
      POST kbn:/api/fleet/agent_download_sources
      {
      "id": "test_id",
      "name": "test_name",
      "host": "https://test.url",
      "is_default": true
      }
    • Response:
      {
      "item": {
        "id": "test_id",
        "name": "test_name",
        "host": "https://test.url",
        "is_default": true,
        "proxy_id": null
      }
      }
  2. Get the available download sources using GET kbn:/api/fleet/agent_download_sources
    • Dev Tools query:
      GET kbn:/api/fleet/agent_download_sources
    • Response:
      {
      "items": [
        {
          "id": "test_id",
          "name": "test_name",
          "host": "https://test.url",
          "is_default": true,
          "proxy_id": null
        },
        {
          "id": "fleet-default-download-source",
          "name": "Elastic Artifacts",
          "is_default": false,
          "host": "https://artifacts.elastic.co/downloads/"
        }
      ],
      "page": 1,
      "perPage": 10000,
      "total": 2
      }
  3. Run again the POST command without is_default key, return 409 error (expected):
    • Dev Tools query
      POST kbn:/api/fleet/agent_download_sources
      {
      "id": "test_id",
      "name": "test_name",
      "host": "https://test.url"
      }
    • Response:
      {
      "statusCode": 409,
      "error": "Conflict",
      "message": """[ingest-download-sources:test_id]: version conflict, document already exists (current version [1]): version_conflict_engine_exception
      Root causes:
          version_conflict_engine_exception: [ingest-download-sources:test_id]: version conflict, document already exists (current version [1])"""
      }
  4. Get the available download sources using GET kbn:/api/fleet/agent_download_sources. New source keeps being the default one.
    • Dev Tools query:
      GET kbn:/api/fleet/agent_download_sources
    • Response:
      {
      "items": [
        {
          "id": "test_id",
          "name": "test_name",
          "host": "https://test.url",
          "is_default": true,
          "proxy_id": null
        },
        {
          "id": "fleet-default-download-source",
          "name": "Elastic Artifacts",
          "is_default": false,
          "host": "https://artifacts.elastic.co/downloads/"
        }
      ],
      "page": 1,
      "perPage": 10000,
      "total": 2
      }
  5. Run again the same POST command as in first step, return 409 error (expected):
    • Dev Tools query
      POST kbn:/api/fleet/agent_download_sources
      {
      "id": "test_id",
      "name": "test_name",
      "host": "https://test.url",
      "is_default": true
      }
    • Response:
      {
      "statusCode": 409,
      "error": "Conflict",
      "message": """[ingest-download-sources:test_id]: version conflict, document already exists (current version [2]): version_conflict_engine_exception
      Root causes:
          version_conflict_engine_exception: [ingest-download-sources:test_id]: version conflict, document already exists (current version [2])"""
      }
  6. Check the available sources again (same query as above):
    • Dev Tools query:
      GET kbn:/api/fleet/agent_download_sources
    • Response: Latest source added changed is_default value to false:
      {
      "items": [
        {
          "id": "fleet-default-download-source",
          "name": "Elastic Artifacts",
          "is_default": false,
          "host": "https://artifacts.elastic.co/downloads/"
        },
        {
          "id": "test_id",
          "name": "test_name",
          "host": "https://test.url",
          "is_default": false,
          "proxy_id": null
        }
      ],
      "page": 1,
      "perPage": 10000,
      "total": 2
      }

Expected behavior:

elasticmachine commented 4 months ago

Pinging @elastic/fleet (Team:Fleet)