---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "docs"
      body:
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    bulk:
      body:
      - index:
          _index: "docs"
          _id: "1"
      - field: "foo"
      - index:
          _index: "docs"
          _id: "2"
      - field: "bar"
      - index:
          _index: "docs"
          _id: "3"
      - field: "baz"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    snapshot.create_repository:
      repository: "repository-fs"
      body:
        type: "fs"
        settings:
          location: "repository-fs"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    snapshot.delete:
      repository: "repository-fs"
      snapshot: "snapshot"
      ignore: 404
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    snapshot.create:
      repository: "repository-fs"
      snapshot: "snapshot"
      wait_for_completion: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.delete:
      index: "docs"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Tests searchable snapshots usage stats:
- requires:
    cluster_features:
    - "gte_v7.12.0"
    reason: "storage flag introduced in 7.12.0"
- do:
    xpack.usage: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    searchable_snapshots.available: true
- match:
    searchable_snapshots.enabled: true
- match:
    searchable_snapshots.indices_count: 0
- do:
    searchable_snapshots.mount:
      repository: "repository-fs"
      snapshot: "snapshot"
      wait_for_completion: true
      storage: "full_copy"
      body:
        index: "docs"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    snapshot.snapshot: "snapshot"
- match:
    snapshot.shards.failed: 0
- match:
    snapshot.shards.successful: 1
- do:
    xpack.usage: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    searchable_snapshots.available: true
- match:
    searchable_snapshots.enabled: true
- match:
    searchable_snapshots.indices_count: 1
---
Tests searchable snapshots usage stats with full_copy and shared_cache indices:
- requires:
    cluster_features:
    - "gte_v7.13.0"
    reason: "extra full_copy and shared_cache fields introduced in 7.13.0"
- do:
    xpack.usage: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    searchable_snapshots.available: true
- match:
    searchable_snapshots.enabled: true
- match:
    searchable_snapshots.indices_count: 0
- match:
    searchable_snapshots.full_copy_indices_count: 0
- match:
    searchable_snapshots.shared_cache_indices_count: 0
- do:
    searchable_snapshots.mount:
      repository: "repository-fs"
      snapshot: "snapshot"
      wait_for_completion: true
      storage: "full_copy"
      body:
        index: "docs"
        renamed_index: "docs_full_copy"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    snapshot.snapshot: "snapshot"
- match:
    snapshot.shards.failed: 0
- match:
    snapshot.shards.successful: 1
- do:
    xpack.usage: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    searchable_snapshots.available: true
- match:
    searchable_snapshots.enabled: true
- match:
    searchable_snapshots.indices_count: 1
- match:
    searchable_snapshots.full_copy_indices_count: 1
- match:
    searchable_snapshots.shared_cache_indices_count: 0
- do:
    searchable_snapshots.mount:
      repository: "repository-fs"
      snapshot: "snapshot"
      wait_for_completion: true
      storage: "shared_cache"
      body:
        index: "docs"
        renamed_index: "docs_shared_cache"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    snapshot.snapshot: "snapshot"
- match:
    snapshot.shards.failed: 0
- match:
    snapshot.shards.successful: 1
- do:
    xpack.usage: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    searchable_snapshots.available: true
- match:
    searchable_snapshots.enabled: true
- match:
    searchable_snapshots.indices_count: 2
- match:
    searchable_snapshots.full_copy_indices_count: 1
- match:
    searchable_snapshots.shared_cache_indices_count: 1
