---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings"
    - "allowed_warnings_regex"
- do:
    allowed_warnings:
    - "index [.ml-inference-000003] matches multiple legacy templates [.ml-inference-000003,\
      \ global], composable templates will only match a single template"
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_trained_model:
      model_id: "a-unused-regression-model1"
      body: "{\n  \"description\": \"empty model for tests\",\n  \"tags\": [\"regression\"\
        , \"tag1\"],\n  \"input\": {\"field_names\": [\"field1\", \"field2\"]},\n\
        \  \"inference_config\": {\"regression\": {}},\n  \"definition\": {\n    \
        \ \"preprocessors\": [],\n     \"trained_model\": {\n        \"tree\": {\n\
        \           \"feature_names\": [\"field1\", \"field2\"],\n           \"tree_structure\"\
        : [\n              {\"node_index\": 0, \"leaf_value\": 1}\n           ],\n\
        \           \"target_type\": \"regression\"\n        }\n     }\n  }\n}\n"
    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:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_trained_model:
      model_id: "a-unused-regression-model"
      body: "{\n  \"description\": \"empty model for tests\",\n  \"tags\": [\"regression\"\
        , \"tag1\"],\n  \"input\": {\"field_names\": [\"field1\", \"field2\"]},\n\
        \  \"inference_config\": {\"regression\": {}},\n  \"definition\": {\n    \
        \ \"preprocessors\": [],\n     \"trained_model\": {\n        \"tree\": {\n\
        \           \"feature_names\": [\"field1\", \"field2\"],\n           \"tree_structure\"\
        : [\n              {\"node_index\": 0, \"leaf_value\": 1}\n           ],\n\
        \           \"target_type\": \"regression\"\n        }\n     }\n  }\n}\n"
    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:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_trained_model:
      model_id: "another-regression-model"
      body: "{\n  \"description\": \"empty model for tests\",\n  \"tags\": [\"regression\"\
        , \"tag1\"],\n  \"input\": {\"field_names\": [\"field1\", \"field2\"]},\n\
        \  \"inference_config\": {\"regression\": {}},\n  \"definition\": {\n    \
        \ \"preprocessors\": [],\n     \"trained_model\": {\n        \"tree\": {\n\
        \           \"feature_names\": [\"field1\", \"field2\"],\n           \"tree_structure\"\
        : [\n              {\"node_index\": 0, \"leaf_value\": 1}\n           ],\n\
        \           \"target_type\": \"regression\"\n        }\n     }\n  }\n}\n"
    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:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_trained_model_alias:
      model_alias: "my-regression"
      model_id: "a-unused-regression-model1"
    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"
---
Test get stats given missing trained model:
- do:
    catch: "missing"
    ml.get_trained_models_stats:
      model_id: "missing-trained-model"
    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"
---
Test get stats given expression without matches and allow_no_match is false:
- do:
    catch: "missing"
    ml.get_trained_models_stats:
      model_id: "missing-trained-model*"
      allow_no_match: false
    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"
---
Test get stats given expression without matches and allow_no_match is true:
- do:
    ml.get_trained_models_stats:
      model_id: "missing-trained-model*"
      allow_no_match: 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"
- match:
    count: 0
- match:
    trained_model_stats: []
---
Test get stats given trained models:
- do:
    ml.get_trained_models_stats:
      model_id: "a-unused-regression-model"
    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:
    count: 1
- do:
    ml.get_trained_models_stats:
      model_id: "_all"
    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:
    count: 4
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model"
- match:
    trained_model_stats.0.pipeline_count: 0
- is_false: "trained_model_stats.0.ingest"
- match:
    trained_model_stats.1.model_id: "a-unused-regression-model1"
- match:
    trained_model_stats.1.pipeline_count: 0
- is_false: "trained_model_stats.1.ingest"
- match:
    trained_model_stats.2.pipeline_count: 0
- is_false: "trained_model_stats.2.ingest"
- do:
    ml.get_trained_models_stats:
      model_id: "*"
    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:
    count: 4
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model"
- match:
    trained_model_stats.0.pipeline_count: 0
- is_false: "trained_model_stats.0.ingest"
- match:
    trained_model_stats.1.model_id: "a-unused-regression-model1"
- match:
    trained_model_stats.1.pipeline_count: 0
- is_false: "trained_model_stats.1.ingest"
- match:
    trained_model_stats.2.pipeline_count: 0
- is_false: "trained_model_stats.2.ingest"
- do:
    ml.get_trained_models_stats:
      model_id: "a-unused-regression-model*"
    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:
    count: 2
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model"
- match:
    trained_model_stats.0.pipeline_count: 0
- is_false: "trained_model_stats.0.ingest"
- match:
    trained_model_stats.1.model_id: "a-unused-regression-model1"
- match:
    trained_model_stats.1.pipeline_count: 0
- is_false: "trained_model_stats.1.ingest"
- do:
    ml.get_trained_models_stats:
      model_id: "a-unused-regression-model*"
      size: 1
    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:
    count: 2
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model"
- match:
    trained_model_stats.0.pipeline_count: 0
- is_false: "trained_model_stats.0.ingest"
- do:
    ml.get_trained_models_stats:
      model_id: "a-unused-regression-model*"
      from: 1
      size: 1
    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:
    count: 2
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model1"
- match:
    trained_model_stats.0.pipeline_count: 0
- is_false: "trained_model_stats.0.ingest"
- do:
    ml.get_trained_models_stats:
      model_id: "another-regression-model"
    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:
    count: 1
- match:
    trained_model_stats.0.model_id: "another-regression-model"
- match:
    trained_model_stats.0.pipeline_count: 0
- do:
    ml.get_trained_models_stats:
      model_id: "my-regression"
    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:
    count: 1
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model1"
- do:
    ml.get_trained_models_stats:
      model_id: "my-regression,another-regression-model"
    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:
    count: 2
- match:
    trained_model_stats.0.model_id: "a-unused-regression-model1"
- match:
    trained_model_stats.1.model_id: "another-regression-model"
