Covers advanced topics (different config options and scenarios)
The following configuration options are available to control the behaviour of the SDK. You can pass the configuration in as options when the SDK client is created.
# Create a Feature Flag Client
client = CfClient(apiKey,
with_base_url("https://config.ff.harness.io/api/1.0"),
with_events_url("https://events.ff.harness.io/api/1.0"),
with_stream_enabled(True),
with_analytics_enabled(True),
Config(pull_interval=60))
Name | Config Option | Description | default |
---|---|---|---|
baseUrl | with_base_url("https://config.ff.harness.io/api/1.0") | the URL used to fetch feature flag evaluations. You should change this when using the Feature Flag proxy to http://localhost:7000 | https://config.ff.harness.io/api/1.0 |
eventsUrl | with_events_url("https://events.ff.harness.io/api/1.0"), | the URL used to post metrics data to the feature flag service. You should change this when using the Feature Flag proxy to http://localhost:7000 | https://events.ff.harness.io/api/1.0 |
pollInterval | Config(pull_interval=60) | when running in stream mode, the interval in seconds that we poll for changes. | 60 |
enableStream | with_stream_enabled(True), | Enable streaming mode. | true |
enableAnalytics | with_analytics_enabled(True) | Enable analytics. Metrics data is posted every 60s | true |
pollInterval | with_poll_interval(120) | When running in stream mode, the interval in seconds that we poll for changes. | 60 |
The SDK provides a logger that wraps the standard python logging package. You can import and use it with:
from featureflags.util import log
log.info("Hello, World!")
If you want to change the default log level, you can use the standard logging levels
from featureflags.util import log
import logging
log.setLevel(logging.WARN)
client.string_variation('identifier_of_your_string_flag', target, "default string")
client.number_variation('identifier_of_your_number_flag', target, -1)
client.json_variation('identifier_of_your_json_flag', target, {})
Call the close function on the client
client.close()
When using your Feature Flag SDKs with a Harness Relay Proxy you need to change the default URL.
To do this you import the url helper functions
from featureflags.config import with_base_url
from featureflags.config import with_events_url
Then pass them with the new URLs when creating your client.
client = CfClient(api_key,
with_base_url("https://config.feature-flags.uat.harness.io/api/1.0"),
with_events_url("https://event.feature-flags.uat.harness.io/api/1.0"))