cloudfoundry / cloud_controller_ng

Cloud Foundry Cloud Controller
Apache License 2.0
193 stars 359 forks source link

Creating a deployment that violates a quota results in 500 unknown error #1683

Closed selzoc closed 4 years ago

selzoc commented 4 years ago

Observed behavior when creating a deployment that will result in more memory usage than the quota allows:

cf7 restart app --strategy rolling

REQUEST: [2020-06-05T08:27:02-07:00]
POST /v3/deployments HTTP/1.1
{
  "relationships": {
    "app": {
      "data": {
        "guid": "a808ccb9-ac53-477f-a921-742f64f1b5ac"
      }
    }
  }
}

RESPONSE: [2020-06-05T08:27:03-07:00]
HTTP/1.1 500 Internal Server Error
{
  "errors": [
    {
      "code": 10001,
      "detail": "An unknown error occurred.",
      "title": "UnknownError"
    }
  ]
}

Unexpected Response
Response Code: 500
Request ID:    7c985db6-0e25-41d1-5332-5ff96499b6ff::8d8e584f-2336-4daf-81b7-83056ab5eb30
Code: 0, Title: , Detail: {
  "errors": [
    {
      "title": "UnknownError",
      "detail": "An unknown error occurred.",
      "code": 10001
    }
  ]
}
FAILED

consulting the cc logs:

{"timestamp":1591370826.70637,
"message":"Request failed: 500: {\"errors\"=>[{\"title\"=>\"UnknownError\", 
\"detail\"=>\"An unknown error occurred.\", \"code\"=>10001, \"test_mode_info\"=>
{\"detail\"=>\"memory quota_exceeded\", \
"title\"=>\"CF-ValidationFailed\", \"backtrace\"=>[
...
cloud_controller_ng/app/actions/deployment_create.rb:69:in `block in create'
...
]}...

This line is

process.reload.update(state: ProcessModel::STARTED)

so the validation must fail on the update, and we don't rescue the error properly. This should be a 422 and return a useful error to the client

This behavior is much much worse than when a quota is violated in a non-deployment scenario:

cf6 push app -v
...
REQUEST: [2020-06-05T08:24:28-07:00]
PUT /v2/apps/74ae2f9f-251b-447d-a51f-5194acae087e HTTP/1.1
{
  "state": "STARTED"
}

RESPONSE: [2020-06-05T08:24:28-07:00]
HTTP/1.1 400 Bad Request
{
  "code": 100005,
  "description": "You have exceeded your organization's memory limit: app requested more memory than available",
  "error_code": "CF-AppMemoryQuotaExceeded"
}
...
You have exceeded your organization's memory limit: app requested more memory than available
FAILED
cf7 push app -v
...
REQUEST: [2020-06-05T08:25:35-07:00]
POST /v3/apps/74ae2f9f-251b-447d-a51f-5194acae087e/actions/restart HTTP/1.1

RESPONSE: [2020-06-05T08:25:35-07:00]
HTTP/1.1 422 Unprocessable Entity
...
{
  "errors": [
    {
      "code": 10008,
      "detail": "memory quota_exceeded",
      "title": "CF-UnprocessableEntity"
    }
  ]
}
...
memory quota_exceeded
FAILED
cf-gitbot commented 4 years ago

We have created an issue in Pivotal Tracker to manage this:

https://www.pivotaltracker.com/story/show/173197856

The labels on this github issue will be updated when the story is started.