peak-sdk 1.11.0__py3-none-any.whl → 1.13.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. peak/__init__.py +3 -2
  2. peak/_metadata.py +185 -1
  3. peak/_version.py +1 -1
  4. peak/callbacks.py +22 -2
  5. peak/cli/cli.py +2 -0
  6. peak/cli/helpers.py +2 -0
  7. peak/cli/metrics/__init__.py +21 -0
  8. peak/cli/metrics/metrics.py +707 -0
  9. peak/cli/press/apps/deployments.py +12 -6
  10. peak/cli/press/apps/specs.py +20 -0
  11. peak/cli/press/blocks/deployments.py +5 -6
  12. peak/cli/press/blocks/specs.py +2 -0
  13. peak/cli/press/deployments.py +49 -3
  14. peak/cli/resources/services.py +20 -5
  15. peak/handler.py +16 -7
  16. peak/metrics/__init__.py +26 -0
  17. peak/metrics/metrics.py +553 -0
  18. peak/output.py +9 -1
  19. peak/press/apps.py +100 -5
  20. peak/press/blocks.py +2 -0
  21. peak/press/deployments.py +35 -0
  22. peak/resources/__init__.py +10 -1
  23. peak/resources/services.py +5 -2
  24. peak/sample_yaml/metrics/create_collection.yaml +8 -0
  25. peak/sample_yaml/metrics/publish.yaml +6 -0
  26. peak/sample_yaml/metrics/query.yaml +25 -0
  27. peak/sample_yaml/press/apps/deployments/create_app_deployment.yaml +12 -0
  28. peak/sample_yaml/press/apps/deployments/create_app_deployment_revision.yaml +12 -0
  29. peak/sample_yaml/press/apps/specs/create_app_spec.yaml +63 -0
  30. peak/sample_yaml/press/apps/specs/create_app_spec_release.yaml +63 -0
  31. peak/sample_yaml/press/blocks/specs/service/api/create_block_spec.yaml +28 -28
  32. peak/sample_yaml/press/blocks/specs/service/api/create_block_spec_release.yaml +28 -28
  33. peak/sample_yaml/press/blocks/specs/service/webapp/create_block_spec.yaml +29 -28
  34. peak/sample_yaml/press/blocks/specs/service/webapp/create_block_spec_release.yaml +29 -28
  35. peak/sample_yaml/press/blocks/specs/workflow/create_block_spec.yaml +32 -32
  36. peak/sample_yaml/press/blocks/specs/workflow/create_block_spec_release.yaml +32 -32
  37. peak/sample_yaml/press/patch_parameters.yaml +9 -0
  38. peak/sample_yaml/resources/services/create_or_update_service.yaml +1 -0
  39. peak/sample_yaml/resources/services/create_service.yaml +1 -0
  40. peak/sample_yaml/resources/services/update_service.yaml +1 -0
  41. peak/sample_yaml/resources/webapps/create_or_update_webapp.yaml +1 -0
  42. peak/sample_yaml/resources/webapps/create_webapp.yaml +1 -0
  43. peak/sample_yaml/resources/webapps/update_webapp.yaml +1 -0
  44. {peak_sdk-1.11.0.dist-info → peak_sdk-1.13.0.dist-info}/METADATA +45 -7
  45. {peak_sdk-1.11.0.dist-info → peak_sdk-1.13.0.dist-info}/RECORD +48 -40
  46. {peak_sdk-1.11.0.dist-info → peak_sdk-1.13.0.dist-info}/LICENSE +0 -0
  47. {peak_sdk-1.11.0.dist-info → peak_sdk-1.13.0.dist-info}/WHEEL +0 -0
  48. {peak_sdk-1.11.0.dist-info → peak_sdk-1.13.0.dist-info}/entry_points.txt +0 -0
@@ -66,10 +66,13 @@ def create(
66
66
  imageUrl (string | required: false): URL of the image to be associated with the app deployment.
67
67
  tags (list(map) | required: false):
68
68
  - name (string): Name of the tag.
69
+ appParameters (map | required: false):
70
+ build (map | required: false): Dictionary of parameters specific to the 'build' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
71
+ run (map | required: false): Dictionary of parameters specific to the 'run' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
69
72
  parameters (map | required: false):
70
- <blockName> (map): Dictionary of parameters for the block. Here the key is the name of the block.
71
- <parameterType> (map): Dictionary of parameters. Here the key is the type of the parameter. Accepted values are "build" or "run".
72
- <parameterName> (string | boolean | number | list(string)): Value of the parameter. Here the key is the name of the parameter.
73
+ <blockName> (map): Dictionary of parameters specific to each block, where each key represents the block name.
74
+ build (map | required: false): Dictionary of parameters for the block's 'build' phase. Keys are parameter names, and values can be of type string, boolean, number, dictionary or list (string, number, dictionary).
75
+ run (map | required: false): Dictionary of parameters for the block's 'run' phase. Keys are parameter names, and values can be of type string, boolean, number, dictionary or list (string, number, dictionary).
73
76
  revision (map | required: false):
74
77
  notes (string | required: false): Notes for the deployment revision.
75
78
  spec (map):
@@ -348,10 +351,13 @@ def create_revision(
348
351
  🧩 ***Input file schema (yaml):***<br/>
349
352
  ```yaml
350
353
  body (map):
354
+ appParameters (map | required: false):
355
+ build (map | required: false): Dictionary of parameters specific to the 'build' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
356
+ run (map | required: false): Dictionary of parameters specific to the 'run' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
351
357
  parameters (map | required: false):
352
- <blockName> (map): Dictionary of blocks within the app, for which to provide parameters. Must be a valid block name.
353
- <parameterType> (map): Dictionary of parameters. Here the key is the type of the parameter. Accepted values are "build" or "run".
354
- <parameterName> (string | boolean | number | list(string)): Value of the parameter. Here the key is the name of the parameter.
358
+ <blockName> (map): Dictionary of parameters specific to each block, where each key represents the block name.
359
+ build (map | required: false): Dictionary of parameters for the block's 'build' phase. Keys are parameter names, and values can be of type string, boolean, number, dictionary or list (string, number, dictionary).
360
+ run (map | required: false): Dictionary of parameters for the block's 'run' phase. Keys are parameter names, and values can be of type string, boolean, number, dictionary or list (string, number, dictionary).
355
361
  release (map):
356
362
  version (string): A valid semantic release version of the app spec.
357
363
  revision (map | required: false):
@@ -76,6 +76,16 @@ def create(
76
76
  release (map):
77
77
  version (string): A valid semantic release version of the block spec.
78
78
  autoRunOnDeploy (bool | required: false): Whether to execute the resource after the app is deployed. By default it is False.
79
+ parameters (map | required: false):
80
+ <parameterType> (list(map)): List containing the parameter objects. Here the key is the type of the parameter. Accepted values are "build" or "run".
81
+ name (string): Name of the parameter.
82
+ type (string): Type of the parameter. Should be one of "boolean", "string", "string_array", "number", "number_array", "object" and "object_array".
83
+ required (boolean): Whether the parameter is required.
84
+ description (string | required: false): Description of the parameter.
85
+ defaultValue (string | required: false): Default value of the parameter.
86
+ title (string | required: false): Title of the parameter.
87
+ options (list(str) | required: false): List of options for the parameter. If provided, it must have at least one object with "title" and "value" field.
88
+ hideValue(boolean | required: false): Can be optionally provided to parameters of type "string", to mask the parameter's value when it has been set at deployment time.
79
89
  ```
80
90
 
81
91
  \b
@@ -332,6 +342,16 @@ def create_release(
332
342
  release (map):
333
343
  version (string): A valid semantic release version of the block spec.
334
344
  autoRunOnDeploy (bool | required: false): Whether to execute the resource after the app is deployed. By default it is False.
345
+ parameters (map | required: false):
346
+ <parameterType> (list(map)): List containing the parameter objects. Here the key is the type of the parameter. Accepted values are "build" or "run".
347
+ name (string): Name of the parameter.
348
+ type (string): Type of the parameter. Should be one of "boolean", "string", "string_array", "number", "number_array", "object" and "object_array".
349
+ required (boolean): Whether the parameter is required.
350
+ description (string | required: false): Description of the parameter.
351
+ defaultValue (string | required: false): Default value of the parameter.
352
+ title (string | required: false): Title of the parameter.
353
+ options (list(str) | required: false): List of options for the parameter. If provided, it must have at least one object with "title" and "value" field.
354
+ hideValue(boolean | required: false): Can be optionally provided to parameters of type "string", to mask the parameter's value when it has been set at deployment time.
335
355
  ```
336
356
 
337
357
  \b
@@ -75,8 +75,8 @@ def create(
75
75
  tags (list(map) | required: false):
76
76
  - name (string): Name of the tag.
77
77
  parameters (map | required: false):
78
- <parameterType> (map): Dictionary of parameters. Here the key is the type of the parameter. Accepted values are "build" or "run".
79
- <parameterName> (string | boolean | number | list(string)): Value of the parameter. Here the key is the name of the parameter.
78
+ build (map | required: false): Dictionary of parameters specific to the 'build' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
79
+ run (map | required: false): Dictionary of parameters specific to the 'run' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
80
80
  revision (map | required: false):
81
81
  notes (string | required: false): Notes for the deployment revision.
82
82
  spec (map):
@@ -362,8 +362,8 @@ def create_revision(
362
362
  ```yaml
363
363
  body (map):
364
364
  parameters (map | required: false):
365
- <parameterType> (map): Dictionary of parameters. Here the key is the type of the parameter. Accepted values are "build" or "run".
366
- <parameterName> (string | boolean | number | list(string)): Value of the parameter. Here the key is the name of the parameter.
365
+ build (map | required: false): Dictionary of parameters specific to the 'build' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
366
+ run (map | required: false): Dictionary of parameters specific to the 'run' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
367
367
  release (map):
368
368
  version (string): A valid semantic release version of the block spec.
369
369
  revision (map | required: false):
@@ -550,8 +550,7 @@ def patch_parameters(
550
550
  \b
551
551
  🧩 ***Input file schema (yaml):***<br/>
552
552
  ```yaml
553
- body (map):
554
- <key> (string | boolean | number | list(string)): Value of the parameter. Here the key is the name of the parameter.
553
+ body (map): Dictionary of parameters specific to the 'run' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
555
554
  ```
556
555
 
557
556
  \b
@@ -330,6 +330,7 @@ def create(
330
330
  env (map | required: false): Key-Value pair where key is the name of the env.
331
331
  secrets (list(str) | required: false): List of secret names to be passed.
332
332
  sessionStickiness (boolean | required: false): Whether to enable session stickiness for the service. It is false by default. To be used only in case of service block of type web-app.
333
+ scaleToZero (boolean | required: false): Enable scale to zero for the service. Only applicable for web-app type services. Default value is false. Enabling Scale to zero ensures that the resources hosting your app are scaled down when ideal over a period of time. The resources will scale back up automatically on next launch.
333
334
  entrypoint (string | required: false): Entry point for the service.
334
335
  healthCheckURL (string | required: false): URL to check the health of the service.
335
336
  minInstances (number | required: false): Minimum number of instances that would run for a service. Default value is 1 and maximum value allowed is 2.
@@ -748,6 +749,7 @@ def create_release(
748
749
  env (map | required: false): Key-Value pair where key is the name of the env.
749
750
  secrets (list(str) | required: false): List of secret names to be passed.
750
751
  sessionStickiness (boolean | required: false): Whether to enable session stickiness for the service. It is false by default. To be used only in case of service block of type web-app.
752
+ scaleToZero (boolean | required: false): Enable scale to zero for the service. Only applicable for web-app type services. Default value is false. Enabling Scale to zero ensures that the resources hosting your app are scaled down when ideal over a period of time. The resources will scale back up automatically on next launch.
751
753
  entrypoint (string | required: false): Entry point for the service.
752
754
  healthCheckURL (string | required: false): URL to check the health of the service.
753
755
  minInstances (number | required: false): Minimum number of instances that would run for a service. Default value is 1 and maximum value allowed is 2.
@@ -23,9 +23,9 @@
23
23
  from typing import List, Optional
24
24
 
25
25
  import typer
26
- from peak.cli import args
27
- from peak.cli.args import OUTPUT_TYPES, PAGING
28
- from peak.constants import OutputTypes
26
+ from peak.cli import args, helpers
27
+ from peak.cli.args import DRY_RUN, GENERATE_YAML, OUTPUT_TYPES, PAGING
28
+ from peak.constants import OutputTypes, OutputTypesNoTable
29
29
  from peak.output import Writer
30
30
  from peak.press.deployments import Deployment
31
31
  from rich.console import Console
@@ -36,6 +36,8 @@ app = typer.Typer(
36
36
  )
37
37
  console = Console()
38
38
 
39
+ _DEPLOYMENT_ID = typer.Argument(..., help="ID of the Block deployment to be used in this operation")
40
+
39
41
 
40
42
  @app.command("list", short_help="List App and Block deployments.")
41
43
  def list_deployments(
@@ -123,3 +125,47 @@ def execute_resources(
123
125
  with writer.pager():
124
126
  response = deployment_client.execute_resources(deployment_id)
125
127
  writer.write(response)
128
+
129
+
130
+ @app.command(short_help="Update the parameters for a deployment at run time.")
131
+ def patch_parameters(
132
+ ctx: typer.Context,
133
+ deployment_id: str = _DEPLOYMENT_ID,
134
+ file: str = args.TEMPLATE_PATH,
135
+ params_file: Optional[str] = args.TEMPLATE_PARAMS_FILE,
136
+ params: Optional[List[str]] = args.TEMPLATE_PARAMS,
137
+ dry_run: Optional[bool] = DRY_RUN, # noqa: ARG001
138
+ paging: Optional[bool] = PAGING, # noqa: ARG001
139
+ output_type: Optional[OutputTypesNoTable] = OUTPUT_TYPES, # noqa: ARG001
140
+ generate: Optional[bool] = GENERATE_YAML, # noqa: ARG001
141
+ ) -> None:
142
+ """***Update*** the parameters for a deployment at run time.
143
+
144
+ \b
145
+ 🧩 ***Input file schema (yaml):***<br/>
146
+ ```yaml
147
+ body (map): Dictionary of parameters specific to the 'run' phase. Keys are parameter names, and values are the parameter values, which can be of type string, boolean, number, dictionary or list (string, number, dictionary).
148
+ ```
149
+
150
+ \b
151
+ 📝 ***Example usage:***
152
+ ```bash
153
+ peak deployments patch-parameters <deployment-id> /path/to/body.yaml -v /path/to/params.yaml
154
+ ```
155
+
156
+ \b
157
+ 🆗 ***Response:***
158
+ ```
159
+ {...}
160
+ ```
161
+
162
+ 🔗 [**API Documentation**](https://press.peak.ai/api-docs/index.htm#/Deployment%20Parameters/patch_v1_deployments__deploymentId__parameters_run)
163
+ """
164
+ body = helpers.template_handler(file, params_file, params)
165
+ deployments_client: Deployment = ctx.obj["client"]
166
+ body = helpers.remove_unknown_args(body, deployments_client.patch_parameters)
167
+ writer: Writer = ctx.obj["writer"]
168
+
169
+ with writer.pager():
170
+ response = deployments_client.patch_parameters(deployment_id, **body)
171
+ writer.write(response)
@@ -79,6 +79,11 @@ SESSION_STICKINESS = typer.Option(
79
79
  help="Enable session stickiness for the service. Not required for API type services.",
80
80
  )
81
81
 
82
+ SCALE_TO_ZERO = typer.Option(
83
+ None,
84
+ help="Enable scale to zero for the service. Only applicable for web-app type services.",
85
+ )
86
+
82
87
  _ENVS = typer.Option(None, help="List of plain text environment variables in the format arg1=value1.")
83
88
 
84
89
  _SECRETS = typer.Option(None, help="List of secret names to be passed as environment variables.")
@@ -168,6 +173,7 @@ def create(
168
173
  version_id: int = VERSION_ID,
169
174
  instance_type_id: int = INSTANCE_TYPE_ID,
170
175
  session_stickiness: bool = SESSION_STICKINESS,
176
+ scale_to_zero: bool = SCALE_TO_ZERO,
171
177
  service_type: Optional[str] = _SERVICE_TYPE,
172
178
  env: Optional[List[str]] = _ENVS,
173
179
  secrets: Optional[List[str]] = _SECRETS,
@@ -198,6 +204,7 @@ def create(
198
204
  env (map | required: false): Key-Value pair where key is the name of the env.
199
205
  secrets (list(str) | required: false): List of secret names to be passed.
200
206
  sessionStickiness (boolean | required: false): Enable session stickiness for the service. Default value is false. Enabling session stickiness will tie each user to a specific server for all their requests. Not required for API type services.
207
+ scaleToZero (boolean | required: false): Enable scale to zero for the service. Only applicable for web-app type services. Default value is false. Enabling Scale to zero ensures that the resources hosting your app are scaled down when ideal over a period of time. The resources will scale back up automatically on next launch.
201
208
  entrypoint (string | required: false): Entrypoint for the service.
202
209
  healthCheckURL (string | required: false): Endpoint to monitor service's operational status.
203
210
  minInstances (number | required: false): Minimum number of instances that would run for a service. Default value is 1 and maximum value allowed is 2.
@@ -212,7 +219,7 @@ def create(
212
219
  \b
213
220
  📝 ***Example usage without yaml:***
214
221
  ```bash
215
- peak services create --name <name> --title <title> --description <description> --service-type web-app --image-id <image-id> --version-id <version-id> --instance-type-id <instance-type-id> --session-stickiness
222
+ peak services create --name <name> --title <title> --description <description> --service-type web-app --image-id <image-id> --version-id <version-id> --instance-type-id <instance-type-id> --scale-to-zero
216
223
  ```
217
224
 
218
225
  \b
@@ -236,6 +243,7 @@ def create(
236
243
  version_id,
237
244
  instance_type_id,
238
245
  session_stickiness,
246
+ scale_to_zero,
239
247
  service_type,
240
248
  env,
241
249
  secrets,
@@ -280,6 +288,7 @@ def update(
280
288
  version_id: int = VERSION_ID,
281
289
  instance_type_id: int = INSTANCE_TYPE_ID,
282
290
  session_stickiness: bool = SESSION_STICKINESS,
291
+ scale_to_zero: bool = SCALE_TO_ZERO,
283
292
  env: Optional[List[str]] = _ENVS,
284
293
  secrets: Optional[List[str]] = _SECRETS,
285
294
  entrypoint: Optional[str] = _ENTRYPOINT,
@@ -294,7 +303,7 @@ def update(
294
303
 
295
304
  \b
296
305
  When updating the service, it will trigger a redeployment only under specific conditions.
297
- Redeployment is triggered if you make changes to any of the following parameters: imageId, versionId, instanceTypeId, env, secrets or sessionStickiness.
306
+ Redeployment is triggered if you make changes to any of the following parameters: imageId, versionId, instanceTypeId, env, secrets, scaleToZero or sessionStickiness.
298
307
  However, only modifying the title or description will not trigger a redeployment.
299
308
 
300
309
  With the help of this operation, we can just update the required fields (except name and serviceType) and keep the rest of the fields as it is.
@@ -314,6 +323,7 @@ def update(
314
323
  env (map | required: false): Key-Value pair where key is the name of the env.
315
324
  secrets (list(str) | required: false): List of secret names to be passed.
316
325
  sessionStickiness (boolean | required: false): Enable session stickiness for the service. Default value is false. Enabling session stickiness will tie each user to a specific server for all their requests. Not required for API type services.
326
+ scaleToZero (boolean | required: false): Enable scale to zero for the service. Only applicable for web-app type services. Default value is false. Enabling Scale to zero ensures that the resources hosting your app are scaled down when ideal over a period of time. The resources will scale back up automatically on next launch.
317
327
  entrypoint (string | required: false): Entrypoint for the service.
318
328
  healthCheckURL (string | required: false): Endpoint to monitor service's operational status.
319
329
  minInstances (number | required: false): Minimum number of instances that would run for a service. Default value is 1 and maximum value allowed is 2.
@@ -328,7 +338,7 @@ def update(
328
338
  \b
329
339
  📝 ***Example usage without yaml:***
330
340
  ```bash
331
- peak services update <service-id> --title <title> --description <description> --image-id <image-id> --version-id <version-id> --instance-type-id <instance-type-id> --session-stickiness
341
+ peak services update <service-id> --title <title> --description <description> --image-id <image-id> --version-id <version-id> --instance-type-id <instance-type-id> --scale-to-zero
332
342
  ```
333
343
 
334
344
  \b
@@ -351,6 +361,7 @@ def update(
351
361
  version_id,
352
362
  instance_type_id,
353
363
  session_stickiness,
364
+ scale_to_zero,
354
365
  env,
355
366
  secrets,
356
367
  entrypoint,
@@ -396,6 +407,7 @@ def create_or_update(
396
407
  version_id: int = VERSION_ID,
397
408
  instance_type_id: int = INSTANCE_TYPE_ID,
398
409
  session_stickiness: bool = SESSION_STICKINESS,
410
+ scale_to_zero: bool = SCALE_TO_ZERO,
399
411
  service_type: Optional[str] = _SERVICE_TYPE,
400
412
  env: Optional[List[str]] = _ENVS,
401
413
  secrets: Optional[List[str]] = _SECRETS,
@@ -411,7 +423,7 @@ def create_or_update(
411
423
 
412
424
  \b
413
425
  When updating the service, it will trigger a redeployment only under specific conditions.
414
- Redeployment is triggered if you make changes to any of the following parameters: imageId, versionId, instanceTypeId, env, secrets or sessionStickiness.
426
+ Redeployment is triggered if you make changes to any of the following parameters: imageId, versionId, instanceTypeId, env, secrets, scaleToZero or sessionStickiness.
415
427
  However, only modifying the title or description will not trigger a redeployment.
416
428
 
417
429
  \b
@@ -431,6 +443,7 @@ def create_or_update(
431
443
  env (map | required: false): Key-Value pair where key is the name of the env.
432
444
  secrets (list(str) | required: false): List of secret names to be passed.
433
445
  sessionStickiness (boolean | required: false): Enable session stickiness for the service. Default value is false. Enabling session stickiness will tie each user to a specific server for all their requests. Not required for API type services.
446
+ scaleToZero (boolean | required: false): Enable scale to zero for the service. Only applicable for web-app type services. Default value is false. Enabling Scale to zero ensures that the resources hosting your app are scaled down when ideal over a period of time. The resources will scale back up automatically on next launch.
434
447
  entrypoint (string | required: false): Entrypoint for the service.
435
448
  healthCheckURL (string | required: false): Endpoint to monitor service's operational status.
436
449
  minInstances (number | required: false): Minimum number of instances that would run for a service. Default value is 1 and maximum value allowed is 2.
@@ -445,7 +458,7 @@ def create_or_update(
445
458
  \b
446
459
  📝 ***Example usage without yaml:***
447
460
  ```bash
448
- peak services create-or-update --name <name> --title <title> --description <description> --image-id <image-id> --version-id <version-id> --instance-type-id <instance-type-id> --session-stickiness
461
+ peak services create-or-update --name <name> --title <title> --description <description> --image-id <image-id> --version-id <version-id> --instance-type-id <instance-type-id> --scale-to-zero
449
462
  ```
450
463
 
451
464
  \b
@@ -471,6 +484,7 @@ def create_or_update(
471
484
  version_id,
472
485
  instance_type_id,
473
486
  session_stickiness,
487
+ scale_to_zero,
474
488
  service_type,
475
489
  env,
476
490
  secrets,
@@ -566,6 +580,7 @@ def describe(
566
580
  "instanceTypeId": 1
567
581
  },
568
582
  "sessionStickiness": false,
583
+ "scaleToZero": false,
569
584
  "createdAt": "2020-01-01T18:00:00.000Z",
570
585
  "createdBy": "someone@peak.ai",
571
586
  "updatedAt": "2020-01-01T18:00:00.000Z",
peak/handler.py CHANGED
@@ -95,19 +95,20 @@ class _CombinedMeta(HandlerRegistryMeta, ABCMeta):
95
95
 
96
96
 
97
97
  class AuthRetrySession(requests.Session):
98
- """Session with extra sugar attached."""
98
+ """Session with retries."""
99
99
 
100
- # used in testing, so we can modify the backoff_factor etc. to speed up the tests
101
100
  _DEFAULT_RETRY_CONFIG: ClassVar[Dict[str, Any]] = {
102
101
  "backoff_factor": 2,
103
- "total": 5,
104
- "status_forcelist": [500, 502, 503, 504],
102
+ "total": 3,
103
+ "status_forcelist": [429, 500, 502, 503, 504],
104
+ "allowed_methods": ["GET", "POST", "PUT", "DELETE", "PATCH"],
105
105
  }
106
106
 
107
107
  def _add_retries(self, retry_config: Optional[Dict[str, Any]] = None) -> None:
108
108
  if retry_config is None:
109
109
  retry_config = self._DEFAULT_RETRY_CONFIG
110
110
  adapter = HTTPAdapter(max_retries=Retry(**retry_config))
111
+ self.mount("http://", adapter=adapter)
111
112
  self.mount("https://", adapter=adapter)
112
113
 
113
114
 
@@ -204,7 +205,11 @@ class HandlerUtils(AuthRetrySession):
204
205
  if response.status_code == 413: # noqa: PLR2004
205
206
  raise PayloadTooLargeException(response.json().get("detail", ""))
206
207
 
207
- raise BaseHttpException.REGISTRY[response.status_code](response.json())
208
+ error_response = response.text
209
+ with contextlib.suppress(Exception):
210
+ error_response = response.json()
211
+
212
+ raise BaseHttpException.REGISTRY[response.status_code](error_response)
208
213
 
209
214
 
210
215
  class BaseHandler(ABC, HandlerUtils, metaclass=_CombinedMeta):
@@ -261,9 +266,11 @@ class MultipartFormDataHandler(BaseHandler):
261
266
  Returns:
262
267
  requests.Response: response of the request
263
268
  """
269
+ self._add_retries()
270
+
264
271
  with self.make_artifact(path, self.parse_args(body or {}), ignore_files) as monitor:
265
272
  headers = {**headers, "Content-Type": monitor.content_type}
266
- response: Any = getattr(requests, method.value)(url, data=monitor, headers=headers, **request_kwargs)
273
+ response: Any = getattr(self, method.value)(url, data=monitor, headers=headers, **request_kwargs)
267
274
  return self.handle_response(response)
268
275
 
269
276
 
@@ -299,8 +306,10 @@ class ApplicationJsonHandler(BaseHandler):
299
306
  Returns:
300
307
  requests.Response: response of the request.
301
308
  """
309
+ self._add_retries()
310
+
302
311
  headers = {**headers, "Content-Type": self.CONTENT_TYPE.value}
303
- response: Any = getattr(requests, method.value)(
312
+ response: Any = getattr(self, method.value)(
304
313
  url,
305
314
  params=self.parse_args(params or {}),
306
315
  json=body,
@@ -0,0 +1,26 @@
1
+ #
2
+ # # Copyright © 2024 Peak AI Limited. or its affiliates. All Rights Reserved.
3
+ # #
4
+ # # Licensed under the Apache License, Version 2.0 (the "License"). You
5
+ # # may not use this file except in compliance with the License. A copy of
6
+ # # the License is located at:
7
+ # #
8
+ # # https://github.com/PeakBI/peak-sdk/blob/main/LICENSE
9
+ # #
10
+ # # or in the "license" file accompanying this file. This file is
11
+ # # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
12
+ # # ANY KIND, either express or implied. See the License for the specific
13
+ # # language governing permissions and limitations under the License.
14
+ # #
15
+ # # This file is part of the peak-sdk.
16
+ # # see (https://github.com/PeakBI/peak-sdk)
17
+ # #
18
+ # # You should have received a copy of the APACHE LICENSE, VERSION 2.0
19
+ # # along with this program. If not, see <https://apache.org/licenses/LICENSE-2.0>
20
+ #
21
+ """This exports the `metrics` module from the `peak` package."""
22
+
23
+ from peak.metrics import metrics
24
+ from peak.metrics.metrics import Metric, get_client
25
+
26
+ __all__ = ["metrics", "Metric", "get_client"]