Skip to content

Commit 67e7a3b

Browse files
committed
chore(flagd): add disable metadata option
Signed-off-by: Maks Osowski <[email protected]>
1 parent 345e793 commit 67e7a3b

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def __init__( # noqa: PLR0913
100100
cert_path: typing.Optional[str] = None,
101101
default_authority: typing.Optional[str] = None,
102102
channel_credentials: typing.Optional[grpc.ChannelCredentials] = None,
103+
sync_metadata_disabled: typing.Optional[bool] = None,
103104
):
104105
self.host = env_or_default(ENV_VAR_HOST, DEFAULT_HOST) if host is None else host
105106

@@ -248,3 +249,11 @@ def __init__( # noqa: PLR0913
248249
)
249250

250251
self.channel_credentials = channel_credentials
252+
253+
# TODO: remove the metadata call entirely after https://github.com/open-feature/flagd/issues/1584
254+
# This is a temporary stop-gap solutions to support servers that don't implement sync.GetMetadata
255+
# (see: https://buf.build/open-feature/flagd/docs/main:flagd.sync.v1#flagd.sync.v1.FlagSyncService.GetMetadata).
256+
# Using this option sisables call to sync.GetMetadata
257+
# Disabling will prevent static context from flagd being used in evaluations.
258+
# GetMetadata and this option will be removed.
259+
self.sync_metadata_disabled = sync_metadata_disabled

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/provider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__( # noqa: PLR0913
6464
cert_path: typing.Optional[str] = None,
6565
default_authority: typing.Optional[str] = None,
6666
channel_credentials: typing.Optional[grpc.ChannelCredentials] = None,
67+
sync_metadata_disabled: typing.Optional[bool] = None,
6768
):
6869
"""
6970
Create an instance of the FlagdProvider
@@ -106,6 +107,7 @@ def __init__( # noqa: PLR0913
106107
cert_path=cert_path,
107108
default_authority=default_authority,
108109
channel_credentials=channel_credentials,
110+
sync_metadata_disabled=sync_metadata_disabled,
109111
)
110112
self.enriched_context: dict = {}
111113

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/process/connector/grpc_watcher.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import grpc
88
from google.protobuf.json_format import MessageToDict
9+
from google.protobuf.struct_pb2 import Struct
910

1011
from openfeature.evaluation_context import EvaluationContext
1112
from openfeature.event import ProviderEventDetails
@@ -176,10 +177,17 @@ def listen(self) -> None:
176177

177178
while self.active:
178179
try:
179-
context_values_request = sync_pb2.GetMetadataRequest()
180-
context_values_response: sync_pb2.GetMetadataResponse = (
181-
self.stub.GetMetadata(context_values_request, wait_for_ready=True)
182-
)
180+
context_values_response: sync_pb2.GetMetadataResponse
181+
if self.config.sync_metadata_disabled:
182+
context_values_response = sync_pb2.GetMetadataResponse(
183+
metadata=Struct()
184+
)
185+
else:
186+
context_values_request = sync_pb2.GetMetadataRequest()
187+
context_values_response = self.stub.GetMetadata(
188+
context_values_request, wait_for_ready=True
189+
)
190+
183191
context_values = MessageToDict(context_values_response)
184192

185193
request = sync_pb2.SyncFlagsRequest(**request_args)

0 commit comments

Comments
 (0)