azure app configuration,

Using Feature Flags with Azure App Configuration

Sven Malvik Sven Malvik Connect May 16, 2020 · 5 mins read
Using Feature Flags with Azure App Configuration

Sometimes we would like to test a new feature of an application. Or we would like to disable code junks because they are not fully implemented. Feature toggling, or feature flags make this possible. This post will discuss how I build a spaceship from scratch with Spring Boot and the support of Azure App Configuration to enable and disable features of my spaceship.


Azure App Configuration IntroductionWatch this post on YouTube: Azure App Configuration Introduction

Agenda

  • Few words to trunk based development and why we may consider feature flags
  • How Azure App Configuration Service stores feature flags
  • We build a spaceship with Spring Boot using feature flags

Few words on trunk based development

Trunk based development simply means to work as closely on the master branch as possible avoiding long-living feature branches. We will still have feature branches, but they will be merged as quickly as possible directly to the master branch. Trunk based development prefers many minor changes over few larger changes. The question then is, how can we add new features that are not fully implemented yet when we need to merge often. The answer is with feature flags. More information on trunk based development can be found at https://trunkbaseddevelopment.com.

How Azure App Configuration Service stores feature flags

We will soon build a spaceship with Spring Boot. As spaceships tend to be quit complex systems, we won’t be able to finish the whole product in this post. In fact, we are just getting started for now, and will hide new features behind a feature flag that we will name beta.

As in part one, we are going to work inside Azure Cloud Shell with Bash. Make sure you are in the right subscription and that you have access to your instance of Azure App Configuration.

# Make sure you are in the correct subscription
az account show

# Eventually switch the current subscription
az account set --subscription "YOUR-SUBSCRIPTION"

# Check if your spaceship config-store is still there
az appconfig show --name "spaceship-appc" --resource-group "svenmalvik-rg"

When everything looks fine, we can deploy our beta flag that we will need later to hide new features of our spaceship.

NOTE: The appconfig feature command is still in preview. Azure App Configuration is in GA.

# Creates a new feature flag without asking us for confirmation (--yes)
az appconfig feature set --name "spaceship-appc" --feature "beta" --yes

Azure App Configuration stores feature flags as json objects the same way as ordinary configurations.

Running instance of Azure App Configuration ServiceRunning instance of Azure App Configuration Service

The feature flag is disabled by default, and we have to explicitly enable it. We’ll do this later once we have our spaceship in place including a feature that we want to try out.

{
    "id": "beta",
    "description": null,
    "enabled": false,
    "conditions": {
        "client_filters": []
    }
}

We build a spaceship with Spring Boot using feature flags

I started by following the instructions on Create a Spring Boot app. The problem was that some instructions were wrong, and used very old libraries. So I created pull requests that were quickly merged by Microsoft into the master branch of the Azure Documentation. As a side note, that was super fun and super rewarding. Anyway, I simplified the example, updated the libraries, and put it on GitHub - spaceship-azure-app-config-demo.

Before we start the spaceship, we need to set the connection-string of the App Configuration instance as an environment variable. I have a Mac, so I set it as shown below.

# I showed how to get the connection-string in the previous post
export APP_CONFIGURATION_CONNECTION_STRING="Endpoint=https://spaceship-appc.azconfig.io;Id=UCUX-l9-s0:3mLEfWlVSlM29Y6SAecu;Secret=QTbtHe75woUi+UerdNVvJWB+E5XQZ9kdrm9xYIcwaVI="

Before we discuss how feature flags are implemented into the spaceship, we will look at the behavior by starting it.

# Maven 3.x and Java 8 required
mvn clean install && mvn spring-boot:run

localhost:8080 is now showing us a sneak peak of the future.

Spring Boot Web App with Azure App Configuration feature flag #1Spring Boot Web App with Azure App Configuration feature flag #1

Now, we are enabling the beta-feature, and then looking even further into the future.

# Enabling the feature flag
az appconfig feature enable --name "spaceship-appc" --feature "beta" --yes

Spring Boot Web App with Azure App Configuration feature flag #2Spring Boot Web App with Azure App Configuration feature flag #2

It’s one line that makes this happen featureManager.isEnabledAsync().

@GetMapping(value = {"", "/", "/welcome"})
public String mainWithParam(Model model) {
    // We prefix our flag with featureManagement.
    model.addAttribute("Beta", featureManager.isEnabledAsync("featureManagement.beta").block());
    return "welcome";
}

Responsible for this simplistic code is the microsoft/spring-cloud-azure-java library that I defined in pom.xml.

Conclusion

We have discussed the main point of feature flags in Azure App Configuration Service. We didn’t talk about filters. Feature filters let us enable a feature for only a subset of users. This is great for canary-testing/AB-testing.

Join Newsletter
Get the latest updates right in your inbox. I never spam!
Sven Malvik
Written by Sven Malvik

Latest Stories

Azure App Configuration Introduction

We build this great application that we configure exactly the way it fits into our environments, and then we realize that changing a conf...

May 09, 2020

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Azure App Configuration Introduction #3

After playing around with Azure App Configuration Service and how to read a configuration entry with REST, and then using feature flags i...

May 23, 2020

Understanding Policies in Azure API Management

Policies are the heart of Azure API Management. They let us change the behavior of our APIs in a very flexible manner. Before I dive in t...

Apr 18, 2020

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Using App Configuration in Azure DevOps

Application deployments dependent often on environment specific data like the name of a resource group, location or flags for certain use...

Aug 01, 2020

Sync Azure App Configuration with GitHub Actions

One questions we might ask us when we move our properties files from an application to Azure App Configuration is how we can do this with...

Sep 05, 2020

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

In this post I want to briefly go through the Azure API Management extension for VSCode and how we can debug policies. It’s one of the qu...

Jan 16, 2021

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

Microsoft updated it’s role based exam for AZ-300. It’s now called AZ-303 and launched last year. This certification is a great proof for...

Feb 01, 2021

Latest Stories

Azure App Configuration Introduction

Azure App Configuration Introduction

We build this great application that we configure exactly the way it fits into our environments, and then we realize that changing a conf...

May 09, 2020

Event-Driven Infrastructure with App Configuration

Event-Driven Infrastructure with App Configuration

Azure App Configuration is great for externalizing application configurations. But what if an application is our infrastructure? How coul...

Sep 12, 2020

Azure App Configuration Introduction #3

Azure App Configuration Introduction #3

After playing around with Azure App Configuration Service and how to read a configuration entry with REST, and then using feature flags i...

May 23, 2020

Understanding Policies in Azure API Management

Understanding Policies in Azure API Management

Policies are the heart of Azure API Management. They let us change the behavior of our APIs in a very flexible manner. Before I dive in t...

Apr 18, 2020

How To Manage Azure Virtual Machines

How To Manage Azure Virtual Machines

I will go through the first steps for managing Virtual Machines. We will create a Windows VM, start the Internet Information Service IIS,...

Dec 26, 2020

Using App Configuration in Azure DevOps

Using App Configuration in Azure DevOps

Application deployments dependent often on environment specific data like the name of a resource group, location or flags for certain use...

Aug 01, 2020

Sync Azure App Configuration with GitHub Actions

Sync Azure App Configuration with GitHub Actions

One questions we might ask us when we move our properties files from an application to Azure App Configuration is how we can do this with...

Sep 05, 2020

Introduction to Azure API Management

Introduction to Azure API Management

Azure API Management (APIM) is a way to create consistent and modern API gateways for existing backend services. It provides an interface...

Jan 25, 2021

Logging in Azure API Management

Logging in Azure API Management

This post is a complete step-by-step guide on how to send logs from Azure API Management to Azure Event Hub with PowerShell. We start by ...

Apr 11, 2020

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

How To Debug Policies in Azure API Management. A Step-by-Step Guide.

In this post I want to briefly go through the Azure API Management extension for VSCode and how we can debug policies. It’s one of the qu...

Jan 16, 2021

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

AZ-303 Self-Study Guide for Becoming an Azure Solution Architect

Microsoft updated it’s role based exam for AZ-300. It’s now called AZ-303 and launched last year. This certification is a great proof for...

Feb 01, 2021