github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/api-docs/recommendations.mdx (about) 1 --- 2 layout: api 3 page_title: Recommendations - HTTP API 4 sidebar_title: Recommendations 5 description: >- 6 The /recommendation endpoints are used to query for and interact with Dynamic 7 Application Sizing recommendations. 8 --- 9 10 # Recommendation HTTP API 11 12 The `/recommendation` endpoints are used to query and interact with Dynamic 13 Application Sizing recommendations. 14 15 <EnterpriseAlert> 16 This API endpoint and functionality only exists in 17 Nomad Enterprise. This is not present in the open source version of Nomad. 18 </EnterpriseAlert> 19 20 ## List Recommendations 21 22 This endpoint lists all the currently available recommendations and provides 23 optional filtering of that list. 24 25 | Method | Path | Produces | 26 | ------ | --------------------- | ------------------ | 27 | `GET` | `/v1/recommendations` | `application/json` | 28 29 The table below shows this endpoint's support for 30 [blocking queries](/api-docs#blocking-queries) and 31 [required ACLs](/api-docs#acls). 32 33 | Blocking Queries | ACL Required | 34 | ---------------- | ----------------------------------------------------------------------------------- | 35 | `YES` | `namespace:read-job` or `namespace:submit-recommendation` or `namespace:submit-job` | 36 37 ### Parameters 38 39 - `group` `(string: "")` - Specifies the task group name to filter within a job. If 40 specified, the `job` parameter must also be specified. 41 42 - `job` `(string: "")` - Specifies the job ID to filter the recommendations list by. 43 44 - `namespace` `(string: "default")` - Specifies the namespace to search. Specifying 45 `*` would return all recommendations across all the authorized namespaces. 46 47 - `task` `(string: "")` - Specifies the task name to filter within a job and task 48 group. If specified, the `job` and `group` query parameters must also be 49 specified. 50 51 ### Sample Request 52 53 ```shell-session 54 $ curl \ 55 https://localhost:4646/v1/recommendations 56 ``` 57 58 ```shell-session 59 $ curl \ 60 https://localhost:4646/v1/recommendations?namespace=* 61 ``` 62 63 ```shell-session 64 $ curl \ 65 https://localhost:4646/v1/recommendations?namespace=*&job=example&group=cache&task=redis 66 ``` 67 68 ### Sample Response 69 70 ```json 71 [ 72 { 73 "ID": "cb80a13d-20d8-fb05-db3f-4ea0fe667b1b", 74 "Region": "global", 75 "Namespace": "default", 76 "JobID": "example", 77 "JobVersion": 0, 78 "Group": "cache", 79 "Task": "redis", 80 "Resource": "MemoryMB", 81 "Value": 10, 82 "Current": 200, 83 "Meta": { 84 "nomad_autoscaler.count.capped": true, 85 "nomad_autoscaler.count.original": 6, 86 "nomad_autoscaler.reason_history": [], 87 "nomad_policy_id": "c355d0ec-7aa1-2604-449d-4ec79c813d2c", 88 "num_evaluated_windows": 1148, 89 "window_size": 300000000000 90 }, 91 "Stats": { 92 "min": 2.6640625, 93 "p99": 6.51171875, 94 "max": 6.515625, 95 "mean": 4.816847859995009 96 }, 97 "EnforceVersion": false, 98 "SubmitTime": 1603372587714807000, 99 "CreateIndex": 5193, 100 "ModifyIndex": 10437 101 }, 102 { 103 "ID": "fdd2b5f1-e6ad-110e-75b9-8f9410e1d8ab", 104 "Region": "global", 105 "Namespace": "default", 106 "JobID": "example", 107 "JobVersion": 0, 108 "Group": "cache", 109 "Task": "redis", 110 "Resource": "CPU", 111 "Value": 57, 112 "Current": 500, 113 "Meta": { 114 "window_size": 300000000000, 115 "nomad_policy_id": "b2c64295-4315-2fdc-6158-a27156808729", 116 "num_evaluated_windows": 1117 117 }, 118 "Stats": { 119 "min": 0, 120 "p99": 50, 121 "max": 63.46186447143555, 122 "mean": 0.3649455045779875 123 }, 124 "EnforceVersion": false, 125 "SubmitTime": 1603372287894356000, 126 "CreateIndex": 5275, 127 "ModifyIndex": 10419 128 } 129 ] 130 ``` 131 132 ## Read Recommendation 133 134 This endpoint reads information about a specific recommendation. 135 136 | Method | Path | Produces | 137 | ------ | --------------------------------------- | ------------------ | 138 | `GET` | `/v1/recommendation/:recommendation_id` | `application/json` | 139 140 The table below shows this endpoint's support for 141 [blocking queries](/api-docs#blocking-queries) and 142 [required ACLs](/api-docs#acls). 143 144 | Blocking Queries | ACL Required | 145 | ---------------- | -------------------- | 146 | `YES` | `namespace:read-job` | 147 148 ### Parameters 149 150 - `:recommendation_id` `(string: <required>)`- Specifies the recommendation ID to 151 query. This is specified as part of the path. 152 153 ### Sample Request 154 155 ```shell-session 156 $ curl \ 157 https://localhost:4646/v1/recommendation/cb80a13d-20d8-fb05-db3f-4ea0fe667b1b 158 ``` 159 160 ### Sample Response 161 162 ```json 163 { 164 "ID": "cb80a13d-20d8-fb05-db3f-4ea0fe667b1b", 165 "Region": "global", 166 "Namespace": "default", 167 "JobID": "example", 168 "JobVersion": 0, 169 "Group": "cache", 170 "Task": "redis", 171 "Resource": "MemoryMB", 172 "Value": 10, 173 "Current": 200, 174 "Meta": { 175 "nomad_autoscaler.count.original": 6, 176 "nomad_autoscaler.reason_history": [], 177 "nomad_policy_id": "c355d0ec-7aa1-2604-449d-4ec79c813d2c", 178 "num_evaluated_windows": 1148, 179 "window_size": 300000000000, 180 "nomad_autoscaler.count.capped": true 181 }, 182 "Stats": { 183 "min": 2.6640625, 184 "p99": 6.51171875, 185 "max": 6.515625, 186 "mean": 4.816847859995009 187 }, 188 "EnforceVersion": false, 189 "SubmitTime": 1603372587714807000, 190 "CreateIndex": 5193, 191 "ModifyIndex": 10437 192 } 193 ``` 194 195 ## Apply and Dismiss Recommendations 196 197 This endpoint is used to apply and dismiss recommendations. 198 199 | Method | Path | Produces | 200 | ------ | --------------------------- | ------------------ | 201 | `POST` | `/v1/recommendations/apply` | `application/json` | 202 203 The table below shows this endpoint's support for 204 [blocking queries](/api-docs#blocking-queries) and 205 [required ACLs](/api-docs#acls). 206 207 | Blocking Queries | ACL Required | 208 | ---------------- | --------------------------------------------------------------------------------- | 209 | `NO` | `namespace:submit-job` with `namespace:sentinel-override` if `PolicyOverride` set | 210 211 ### Parameters 212 213 - `Apply` `(array<string>: nil)` - Specifies a set of recommendation IDs to be 214 applied. This results in Nomad applying the recommendation to the job 215 specification and performing a job register. 216 217 - `Dismiss` `(array<string>: nil)` - Specifies a set of recommendation IDs to be 218 dismissed. This results in Nomad deleting them from the state store. 219 220 - `PolicyOverride` `(bool: false)` - If set, any soft mandatory Sentinel policies 221 will be overridden. This allows a recommendation to be applied when it would be 222 denied by a policy. 223 224 ### Sample Payload 225 226 ```json 227 { 228 "Apply": ["cb80a13d-20d8-fb05-db3f-4ea0fe667b1b"] 229 } 230 ``` 231 232 ### Sample Request 233 234 ```shell-session 235 $ curl \ 236 --request POST \ 237 --data @payload.json \ 238 https://localhost:4646/v1/recommendations/apply 239 ``` 240 241 ### Sample Response 242 243 ```json 244 { 245 "Errors": [], 246 "LastIndex": 0, 247 "RequestTime": 0, 248 "UpdatedJobs": [ 249 { 250 "EvalCreateIndex": 51, 251 "EvalID": "3c91a755-f314-e2fb-500b-437ad08e13ea", 252 "JobID": "example", 253 "JobModifyIndex": 51, 254 "Namespace": "default", 255 "Recommendations": ["cb80a13d-20d8-fb05-db3f-4ea0fe667b1b"], 256 "Warnings": "" 257 } 258 ] 259 } 260 ``` 261 262 ## Create or Update a Recommendation 263 264 This endpoint is used to create or update a recommendation. 265 266 | Method | Path | Produces | 267 | ------ | -------------------- | ------------------ | 268 | `POST` | `/v1/recommendation` | `application/json` | 269 270 The table below shows this endpoint's support for 271 [blocking queries](/api-docs#blocking-queries) and 272 [required ACLs](/api-docs#acls). 273 274 | Blocking Queries | ACL Required | 275 | ---------------- | ----------------------------------------------------------- | 276 | `NO` | `namespace:submit-recommendation` or `namespace:submit-job` | 277 278 ### Parameters 279 280 - `ID` `(string: "")` - The ID of an existing recommendation to update. 281 282 - `Region` `(string: "")`- The Nomad region identifier which contains the job 283 that the recommendation is for. If omitted, this defaults to that of the Nomad 284 agent. 285 286 - `Namespace` `(string: "")`- The namespace within which the target job is running 287 within. If omitted, this defaults to `default`. 288 289 - `JobID` `(string: <required>)`- The job ID which this recommendation is for. 290 291 - `Group` `(string: <required>)`- The task group name within the job which this 292 recommendation is for. 293 294 - `Task` `(string: <required>)`- The task name within the task group which this 295 recommendation is for. 296 297 - `Resource` `(string: <required>)`- The resource that the recommendation is for. 298 Possible values are `CPU` and `MemoryMB`. 299 300 - `Value` `(int: <required>)`- The value recommendation for the resource. This 301 must met the minimum requirements which are `1` for `CPU` and `10` for `MemoryMB`. 302 303 - `Meta` `(map<string|...>: nil)`- JSON block that is persisted as part of the 304 recommendation providing arbitrary, useful information. 305 306 - `Stats` `(map<string|float64>: nil)` - A mapping of statistics that are persisted 307 as part of the recommendation providing insight into the recommendation 308 calculation. 309 310 - `EnforceVersion` `(bool: false)`- Indicates that the recommendation is only valid 311 for the current version of the job. Subsequent job updates will automatically 312 dismiss this recommendation. 313 314 ### Sample Payload 315 316 ```json 317 { 318 "Region": "global", 319 "Namespace": "default", 320 "JobID": "example", 321 "Group": "cache", 322 "Task": "redis", 323 "Resource": "MemoryMB", 324 "Value": 512, 325 "Meta": { 326 "nomad_policy_id": "c355d0ec-7aa1-2604-449d-4ec79c813d2c" 327 }, 328 "Stats": { 329 "min": 2.6640625, 330 "p99": 6.51171875, 331 "max": 6.515625, 332 "mean": 4.816847859995009 333 } 334 } 335 ``` 336 337 ### Sample Request 338 339 ```shell-session 340 $ curl \ 341 --request POST \ 342 --data @payload.json \ 343 https://localhost:4646/v1/recommendation 344 ``` 345 346 ### Sample Response 347 348 ```json 349 { 350 "CreateIndex": 22, 351 "Current": 256, 352 "EnforceVersion": false, 353 "Group": "cache", 354 "ID": "47c97404-918f-8b19-873b-36d802f16f23", 355 "JobID": "example", 356 "JobVersion": 0, 357 "Meta": { 358 "nomad_policy_id": "c355d0ec-7aa1-2604-449d-4ec79c813d2c" 359 }, 360 "ModifyIndex": 25, 361 "Namespace": "default", 362 "Region": "global", 363 "Resource": "MemoryMB", 364 "Stats": { 365 "mean": 4.816847859995009, 366 "min": 2.6640625, 367 "p99": 6.51171875, 368 "max": 6.515625 369 }, 370 "SubmitTime": 1603444202372926000, 371 "Task": "redis", 372 "Value": 512 373 } 374 ```