Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds tasks test for serverless #141

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Adds tasks test for serverless #141

merged 1 commit into from
Oct 14, 2024

Conversation

picandocodigo
Copy link
Member

AFAIK we can't see the list of tasks in Serverless, so I wrote a test that catches the 404 when trying to get an invalid task.

"type":"resource_not_found_exception",
"reason":"task [node_id:123456] belongs to the node [node_id] which isn't part of the cluster and there is no record of the task"

@picandocodigo picandocodigo requested a review from a team October 11, 2024 09:24
picandocodigo added a commit to elastic/elasticsearch-serverless-ruby that referenced this pull request Oct 11, 2024
picandocodigo added a commit to elastic/elasticsearch-serverless-ruby that referenced this pull request Oct 11, 2024
picandocodigo added a commit to elastic/elasticsearch-serverless-ruby that referenced this pull request Oct 11, 2024
Copy link
Member

@pquentin pquentin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think that test is fine, I'm just not seeing what that has to do with not being able to list tasks.

@picandocodigo
Copy link
Member Author

@pquentin I mentioned listing tasks because I don't know how we can get the id of a running task from the API in Serverless to use it in task.get.

picandocodigo added a commit to elastic/elasticsearch-serverless-ruby that referenced this pull request Oct 11, 2024
@pquentin
Copy link
Member

Ah got it thanks. You can create a task by calling any API that has a wait_for_completion parameter, such as say the Update by query API. The task id will be in the response.

@picandocodigo
Copy link
Member Author

Even with the task id, if I understand correctly Serverless won't give information on nodes, and the id needs to be node_id:task_id. So I'm not really sure how this API can be used in Serverless 🤔
I'm ok with merging the test as it is anyway.

@pquentin
Copy link
Member

pquentin commented Oct 14, 2024

I've approved last week already, meaning I'm happy to merge this!

I did test however, and yes, this API can be used in Serverless, using those three API calls for example:

PUT /index
POST index/_update_by_query?wait_for_completion=false
GET _tasks/LO253FbxRAutdimOeNX5iw:13676458

The last API call returns this:

{
  "completed": true,
  "task": {
    "node": "serverless",
    "id": 13676458,
    "type": "transport",
    "action": "indices:data/write/update/byquery",
    "status": {
      "total": 0,
      "updated": 0,
      "created": 0,
      "deleted": 0,
      "batches": 0,
      "version_conflicts": 0,
      "noops": 0,
      "retries": {
        "bulk": 0,
        "search": 0
      },
      "throttled_millis": 0,
      "requests_per_second": -1,
      "throttled_until_millis": 0
    },
    "description": "update-by-query [index]",
    "start_time_in_millis": 1728904451130,
    "running_time_in_nanos": 3922972,
    "cancellable": true,
    "cancelled": false,
    "headers": {
      "trace.id": "a0f9f4548e8201332f63305709812b2a"
    }
  },
  "response": {
    "took": 3,
    "timed_out": false,
    "total": 0,
    "updated": 0,
    "created": 0,
    "deleted": 0,
    "batches": 0,
    "version_conflicts": 0,
    "noops": 0,
    "retries": {
      "bulk": 0,
      "search": 0
    },
    "throttled": "0s",
    "throttled_millis": 0,
    "requests_per_second": -1,
    "throttled_until": "0s",
    "throttled_until_millis": 0,
    "failures": []
  }
}

@picandocodigo
Copy link
Member Author

Great, thanks @pquentin! I've updated both tasks tests to include this 👍


- do:
tasks.get: { task_id: $task }
catch: resource_not_found_exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails for me:

AssertionError: Failed to catch 'resource_not_found_exception' in {'completed': True, ...}

I'm assuming the same applies to the stack test. Should we refactor the common part as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouch, sorry, that was me not committing the right code! I've updated it to check for a task key which according to my tests should work even if completed: false.

@picandocodigo picandocodigo merged commit 663126b into main Oct 14, 2024
3 checks passed
@picandocodigo picandocodigo deleted the tasks_serverless branch October 14, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants