-
Notifications
You must be signed in to change notification settings - Fork 2
Support Datadog feature flags #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
3d4fc3a to
e09b016
Compare
e09b016 to
826b998
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a first pass, looking good so far!
a9c82ad to
3315e9c
Compare
3315e9c to
d0ef55f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is my final pass, thanks a lot!
6b8fd15 to
536a5fc
Compare
536a5fc to
d7a0c79
Compare
2165e46 to
e0fc87d
Compare
| VERBOSE = "DDA_VERBOSE" | ||
| NO_DYNAMIC_DEPS = "DDA_NO_DYNAMIC_DEPS" | ||
| TELEMETRY_API_KEY = "DDA_TELEMETRY_API_KEY" | ||
| FEATURE_FLAGS_CLIENT_TOKEN = "DDA_FEATURE_FLAGS_CLIENT_TOKEN" # noqa: S105 This is not a hardcoded secret but the linter complains on it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| FEATURE_FLAGS_CLIENT_TOKEN = "DDA_FEATURE_FLAGS_CLIENT_TOKEN" # noqa: S105 This is not a hardcoded secret but the linter complains on it | |
| FEATURE_FLAGS_CLIENT_TOKEN = "DDA_FEATURE_FLAGS_CLIENT_TOKEN" # noqa: S105 |
| import json | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from httpx import HTTPError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be lazily imported where it's required.
| } | ||
|
|
||
| headers["dd-application-id"] = self.__app_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| headers["dd-application-id"] = self.__app_id | |
| "dd-application-id": self.__app_id, | |
| } |
| self.__cache: dict[tuple[str, str, tuple[tuple[str, str], ...]], Any] = {} | ||
|
|
||
| @cached_property | ||
| def __client_token(self) -> str | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is only used by the client and it feels odd to instantiate the client with potentially no token, requiring the client to check how it was constructed. Can we change this property to create and return a client or None if we can't get a token?
| if isinstance(value, str): | ||
| stringified_attributes[key] = value | ||
| else: | ||
| stringified_attributes[key] = json.dumps(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is desirable. Can we just rely on the backend rejecting bad data?
>>> import json
>>> json.dumps(0)
'0'
>>> json.dumps(None)
'null'
Introduce Feature Flag support inside
ddacommands.Mostly solve the problems described in: https://datadoghq.atlassian.net/wiki/spaces/~7120201870126a495245b69e47156354de0ad9/pages/5569413152/Feature+Flags+dda?atlOrigin=eyJpIjoiZWI5Y2NjNTRhMDViNDc3NmFkYWNlNGVmOGExMjkzY2QiLCJwIjoiYyJ9
In that PR feature flags are only supported when running command locally.
A client token is required and will be fetched using the same mechanism as for the telemetry API key.
The feature flag can be used easily inside the application code by calling
app.features.enabled("flag", "default_value", extra_context)The extra context is not needed, by default the context is populated here and contains info about whether this is a CI run, and the username if it exists