Roll out a service fabric application with LaunchDarkly and VSTS

I showed you in one of my last posts, how easy it is to deploy a service fabric application with VSTS. I demoed this last week at my talk about microservices at the Technical Summit. Normally I do the demo with the VisualObjects project from the getting started samples. This is good to show the automatic update process and self healing. But in reality you don’t want this inconsistent behavior. You want to control the rollout with a feature flag. So this time I did the demo controlling the roll out with a feature flag and LaunchDarkly.

I will show you in the next 5 steps how you can set up your LaunchDarkly account, Install the VSTS extension and configure your project so that you can run the demo yourself.

Creat a LaunchDarkly feature flag

Sign up for a free 30 day trial on the Launchdarkly website. Then log in and create a new feature flag.

new-feature-flag

Name it rotate-object and make it a boolean.

new-feature-flag-dialog

Now go to the LaunchDarkly account settings and copy your access token. You will need this for your service endpoint in VSTS.

Account settings-AcessToken

Install the VSTS Extension

Browse the marketplace and search for LaunchDarkly.

Brows-marketplace

Install the extension to your account.

LaunchDarkly Integration - Visual Studio Marketplace

In the settings of your VSTS project you can now add a service endpoint. Enter the access token you copied from your account settings in the LaunchDarkly portal.

LaunchDarkly-Service-Endpoint

Associate a WorkItem with a feature flag

If you now open a WorkItem you find a new LaunchDarkly tab. Select your service endpoint and the environment and associate your WorkItem to the feature flag your created.

Associate WorkItem with Feature Flag

Setup Code, Build and Release

You can clone my repository from GitHub. Locate VisualObjectActor.cs in VisualObjects.ActorService. At the top of the class are the LdClient and the User members. Initialize the client with the SDK key from your environment. You get the key from the account settings in the LaunchDarkly portal.

Account settings-SDK key

private LdClient client = new LdClient("sdk-88888888-4444-4444-4444-000000000000");
private User user = User.WithKey("kaufm");

Note the code in the MoveObject method. This code is executed every 10 milliseconds per actor. This where you can see that there is nearly no footprint using the feature flag.

if (client.BoolVariation("rotate-object", user, false))
{
    visualObject.Move(true);
}
else
{
    visualObject.Move(false);
}

Now create the build and the release for the solution. This is straight forward and I described it in one of my last posts.

Add Rollout Task to Release

No open the release and add a “LaunchDarkly Rollout” task. Set it to 100% but set the flag state to off. This will allow you to switch on the flag after deployment and you can see how fast the flags have effect.

LaunchDarkly Controlled Rollout

The task needs some release variables so that it can write back information to your WorkItem. I think this is not necessary – the extension should know the project where it runs in. I hope this changes in future versions. For now add a release variable accountName and projectName that point to your team project.

Now depending of the version of the extension you have to set ether alternate credentials or a PAT (private access token). If you’re on V1 set your alternate access credentials.

Alternate authentication credentials

If you’re on V2 then create a PAT.

Personal access tokens

Now set the variables alternateUser and alternatePassword for your credentials. If you use PAt you only have to set the alternatePassword and enter your PAT. There is still a bug in the extension – so you cannot encrypt your PAT write now. The V2 is still a private beta – so I’m sure this will change when the V2 gets released.

Release-variables

Many thanks at this point to the Launchdarkly support. They helped me to get the extension running in a few days so that I was able to make the demo on time with the new version. Thanks, Alexis!

Summary

So – that’s it. Now create a new build and make sure to associate it with the WorkItem that has the feature flag linked to it. Start a release for the build and it will deploy your VisualObject solution to your Service Fabric cluster.

The release summary contains a LaunchDarkly tab that shows the result of your rollout.

Release-overview-integration

if you now open the feature flag in the LaunchDarkly portal you can switch it on and off and the objects start or stop moving right away.

lddemo

One thought on “Roll out a service fabric application with LaunchDarkly and VSTS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s