Example:
Basic Code to use Python and Split REST API to Extract Split names that serve 100% treatment in default rule and have not been changed for a specific time for a given Workspace/Environment, and last received impressions for specific time.
This script is useful to detect old Splits that can be removed from the code as the feature is completely enabled or disabled and no changes done to the Split for certain time.
How to use:
- Class wrapper for Admin API, installation instructions in this link: Python Admin API Library Wrapper
- Script code below, update your relevant Split Admin API Key, the script will loop through all workspaces, environments and splits and check the target dates threshold for Splits last modified and last impressions received dates. The script will print out the split, environment and workspace names.
from splitapiclient.main import get_client
import datetime
#############################################
workspaceName = "Defaults"
environmentName = "Production"
LastModifiedTime= datetime.datetime(2021, 11, 1)
LastTrafficReceived = datetime.datetime(2021, 11, 1)
#############################################
client = get_client({'apikey': 'ADMIN API KEY'})
cuttoffModifiedDate = 1000 * float(LastModifiedTime.strftime('%s'))
trafficReceivedDate = 1000 * float(LastTrafficReceived.strftime('%s'))
finalList = []
for ws in client.workspaces.list():
for env in client.environments.list(ws.id):
for spDef in client.split_definitions.list(env.id, ws.id):
if spDef._lastUpdateTime<cuttoffModifiedDate:
if spDef._lastTrafficReceivedAt>trafficReceivedDate:
for dr in spDef._default_rule:
if dr._size==100:
finalList.append([ws.name, env.name, spDef.name])
print(ws.name+", "+env.name+", "+spDef.name)
Comments
0 comments
Please sign in to leave a comment.