---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v8.13.0"
    reason: "_tsid hashing introduced in 8.13"
- do:
    snapshot.create_repository:
      repository: "test_repo"
      body:
        type: "fs"
        settings:
          location: "test_repo"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
teardown:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    snapshot.delete_repository:
      repository: "test_repo"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Create a snapshot and then restore it:
- requires:
    cluster_features:
    - "gte_v8.2.0"
    reason: "tsdb indexing changed in 8.2.0"
    test_runner_features:
    - "allowed_warnings"
- do:
    indices.create:
      index: "test_index"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "metricset"
            - "k8s.pod.uid"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
            number_of_replicas: 0
            number_of_shards: 2
        mappings:
          properties:
            '@timestamp':
              type: "date"
            metricset:
              type: "keyword"
              time_series_dimension: true
            k8s:
              properties:
                pod:
                  properties:
                    uid:
                      type: "keyword"
                      time_series_dimension: true
                    name:
                      type: "keyword"
                    ip:
                      type: "ip"
                    network:
                      properties:
                        tx:
                          type: "long"
                        rx:
                          type: "long"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    bulk:
      refresh: true
      index: "test_index"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:04.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.1\", \"network\": {\"tx\": 2001818691, \"rx\": 802133794}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:24.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.1\", \"network\": {\"tx\": 2005177954, \"rx\": 801479970}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:44.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.1\", \"network\": {\"tx\": 2006223737, \"rx\": 802337279}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:51:04.467Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cat\", \"uid\":\"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"ip\": \"10.10.55.2\", \"network\": {\"tx\": 2012916202, \"rx\": 803685721}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:03.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434521831, \"rx\": 530575198}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:23.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434577921, \"rx\": 530600088}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:53.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434587694, \"rx\": 530604797}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:51:03.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"dog\", \"uid\":\"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"ip\": \"10.10.55.3\", \"network\": {\"tx\": 1434595272, \"rx\": 530605511}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:03.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cow\", \"uid\":\"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39\"\
        , \"ip\": \"10.10.55.4\", \"network\": {\"tx\": 1434521831, \"rx\": 530575198}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:23.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cow\", \"uid\":\"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39\"\
        , \"ip\": \"10.10.55.4\", \"network\": {\"tx\": 1434577921, \"rx\": 530600088}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:50:53.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cow\", \"uid\":\"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39\"\
        , \"ip\": \"10.10.55.4\", \"network\": {\"tx\": 1434587694, \"rx\": 530604797}}}}"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:51:03.142Z\", \"metricset\": \"pod\", \"\
        k8s\": {\"pod\": {\"name\": \"cow\", \"uid\":\"1c4fc7b8-93b7-4ba8-b609-2a48af2f8e39\"\
        , \"ip\": \"10.10.55.4\", \"network\": {\"tx\": 1434595272, \"rx\": 530605511}}}}"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    cluster.health:
      wait_for_status: "green"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    snapshot.create:
      repository: "test_repo"
      snapshot: "test_restore_tsdb"
      wait_for_completion: true
      body:
        indices: "test_index"
        feature_states:
        - "none"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    snapshot.snapshot: "test_restore_tsdb"
- match:
    snapshot.state: "SUCCESS"
- match:
    snapshot.shards.successful: 2
- match:
    snapshot.shards.failed: 0
- is_true: "snapshot.version"
- gt:
    snapshot.version_id: 0
- do:
    indices.close:
      index: "test_index"
    allowed_warnings:
    - "the default value for the ?wait_for_active_shards parameter will change from\
      \ '0' to 'index-setting' in version 8; specify '?wait_for_active_shards=index-setting'\
      \ to adopt the future default behaviour, or '?wait_for_active_shards=0' to preserve\
      \ today's behaviour"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    snapshot.restore:
      repository: "test_repo"
      snapshot: "test_restore_tsdb"
      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:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    cluster.health:
      wait_for_status: "green"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    status: "green"
- do:
    search:
      index: "test_index"
      body:
        fields:
        - field: "_tsid"
        query:
          query_string:
            query: "+@timestamp:\"2021-04-28T18:51:04.467Z\" +k8s.pod.name:cat"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total.value: 1
- match:
    hits.hits.0._source.k8s.pod.uid: "947e4ced-1786-4e53-9e0c-5c447e959507"
- match:
    hits.hits.0.fields._tsid:
    - "KCjEJ9R_BgO8TRX2QOd6dpR12oDh--qoyNZRQPy43y34Qdy2dpsyG0o"
