Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions api/integrations/launch_darkly/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
BACKOFF_DEFAULT_RETRY_AFTER_SECONDS,
BACKOFF_MAX_RETRIES,
LAUNCH_DARKLY_API_BASE_URL,
LAUNCH_DARKLY_API_FLAGS_LIMIT_PER_PAGE,
LAUNCH_DARKLY_API_ITEM_COUNT_LIMIT_PER_PAGE,
LAUNCH_DARKLY_API_VERSION,
)
Expand Down Expand Up @@ -172,15 +173,32 @@ def get_environments(self, project_key: str) -> list[ld_types.Environment]:
)
)

def get_flags(self, project_key: str) -> list[ld_types.FeatureFlag]:
"""operationId: getFeatureFlags"""
def get_flags(
self,
project_key: str,
environment_keys: list[str] | None = None,
) -> list[ld_types.FeatureFlag]:
"""operationId: getFeatureFlags

:param environment_keys: List of environment keys to include configs for.
In API v20240415, the environments field is only returned when the environment is provided in the request.
Supports multiple values
"""

endpoint = f"/api/v2/flags/{project_key}"
params: dict[str, Any] = {
# Summary should be set to 0 in order to get the full flag data including rules.
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlags!in=query&path=summary&t=request
"summary": "0",
"limit": LAUNCH_DARKLY_API_FLAGS_LIMIT_PER_PAGE,
}
if environment_keys:
# requests library handles list -> repeated params (env=a&env=b)
params["env"] = environment_keys
return list(
self._iter_paginated_items(
collection_endpoint=endpoint,
# Summary should be set to 0 in order to get the full flag data including rules.
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlags!in=query&path=summary&t=request
additional_params={"summary": "0"},
additional_params=params,
)
)

Expand Down
7 changes: 4 additions & 3 deletions api/integrations/launch_darkly/constants.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
LAUNCH_DARKLY_API_BASE_URL = "https://app.launchdarkly.com"
LAUNCH_DARKLY_API_VERSION = "20220603"
# Maximum limit for /api/v2/projects/
# /api/v2/flags/ seemingly not limited, but let's not get too greedy
LAUNCH_DARKLY_API_VERSION = "20240415"
# Maximum limit for /api/v2/projects/ and other endpoints
LAUNCH_DARKLY_API_ITEM_COUNT_LIMIT_PER_PAGE = 1000
# Maximum limit for /api/v2/flags/ is now 100 by launchdarkly API design
LAUNCH_DARKLY_API_FLAGS_LIMIT_PER_PAGE = 100

LAUNCH_DARKLY_IMPORTED_TAG_COLOR = "#3d4db6"
LAUNCH_DARKLY_IMPORTED_DEFAULT_TAG_LABEL = "Imported"
Expand Down
5 changes: 4 additions & 1 deletion api/integrations/launch_darkly/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,10 @@ def process_import_request(

try:
ld_environments = ld_client.get_environments(project_key=ld_project_key)
ld_flags = ld_client.get_flags(project_key=ld_project_key)
ld_flags = ld_client.get_flags(
project_key=ld_project_key,
environment_keys=[env["key"] for env in ld_environments],
)
ld_flag_tags = ld_client.get_flag_tags()
# ld_segment_tags = ld_client.get_segment_tags()
# Keyed by (segment, environment)
Expand Down
2 changes: 1 addition & 1 deletion api/tests/unit/integrations/launch_darkly/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_launch_darkly_client__get_flags__return_expected(
new=api_version,
)
mocker.patch(
"integrations.launch_darkly.client.LAUNCH_DARKLY_API_ITEM_COUNT_LIMIT_PER_PAGE",
"integrations.launch_darkly.client.LAUNCH_DARKLY_API_FLAGS_LIMIT_PER_PAGE",
new=3,
)

Expand Down
Loading