Coverage for /usr/local/lib/python3.12/site-packages/prefect/settings/models/client.py: 100%
17 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
1from typing import ClassVar 1a
3from pydantic import AliasChoices, AliasPath, Field 1a
4from pydantic_settings import SettingsConfigDict 1a
6from prefect.settings.base import ( 1a
7 PrefectBaseSettings,
8 build_settings_config,
9)
10from prefect.types import ClientRetryExtraCodes, JsonStringOrDict 1a
13class ClientMetricsSettings(PrefectBaseSettings): 1a
14 """
15 Settings for controlling metrics reporting from the client
16 """
18 model_config: ClassVar[SettingsConfigDict] = build_settings_config( 1a
19 ("client", "metrics")
20 )
22 enabled: bool = Field( 1a
23 default=False,
24 description="Whether or not to enable Prometheus metrics in the client.",
25 # Using alias for backwards compatibility. Need to duplicate the prefix because
26 # Pydantic does not allow the alias to be prefixed with the env_prefix. The AliasPath
27 # needs to be first to ensure that init kwargs take precedence over env vars.
28 validation_alias=AliasChoices(
29 AliasPath("enabled"),
30 "prefect_client_metrics_enabled",
31 "prefect_client_enable_metrics",
32 ),
33 )
35 port: int = Field( 1a
36 default=4201, description="The port to expose the client Prometheus metrics on."
37 )
40class ClientSettings(PrefectBaseSettings): 1a
41 """
42 Settings for controlling API client behavior
43 """
45 model_config: ClassVar[SettingsConfigDict] = build_settings_config(("client",)) 1a
47 max_retries: int = Field( 1a
48 default=5,
49 ge=0,
50 description="""
51 The maximum number of retries to perform on failed HTTP requests.
52 Defaults to 5. Set to 0 to disable retries.
53 See `PREFECT_CLIENT_RETRY_EXTRA_CODES` for details on which HTTP status codes are
54 retried.
55 """,
56 )
58 retry_jitter_factor: float = Field( 1a
59 default=0.2,
60 ge=0.0,
61 description="""
62 A value greater than or equal to zero to control the amount of jitter added to retried
63 client requests. Higher values introduce larger amounts of jitter.
64 Set to 0 to disable jitter. See `clamped_poisson_interval` for details on the how jitter
65 can affect retry lengths.
66 """,
67 )
69 retry_extra_codes: ClientRetryExtraCodes = Field( 1a
70 default_factory=set,
71 description="""
72 A list of extra HTTP status codes to retry on. Defaults to an empty list.
73 429, 502 and 503 are always retried. Please note that not all routes are idempotent and retrying
74 may result in unexpected behavior.
75 """,
76 examples=["404,429,503", "429", {404, 429, 503}],
77 )
79 csrf_support_enabled: bool = Field( 1a
80 default=True,
81 description="""
82 Determines if CSRF token handling is active in the Prefect client for API
83 requests.
85 When enabled (`True`), the client automatically manages CSRF tokens by
86 retrieving, storing, and including them in applicable state-changing requests
87 """,
88 )
90 custom_headers: JsonStringOrDict = Field( 1a
91 default_factory=dict,
92 description="""
93 Custom HTTP headers to include with every API request to the Prefect server.
94 Headers are specified as key-value pairs. Note that headers like 'User-Agent'
95 and CSRF-related headers are managed by Prefect and cannot be overridden.
96 """,
97 examples=[{"X-Custom-Header": "value"}, {"Authorization": "Bearer token"}],
98 )
100 metrics: ClientMetricsSettings = Field( 1a
101 default_factory=ClientMetricsSettings,
102 description="Settings for controlling metrics reporting from the client",
103 )