azure app configuration,

Azure App Configuration Introduction #3

Sven Malvik Sven Malvik Connect May 23, 2020 · 5 mins read
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 in a Spring Boot application, I got hooked I must admit. I wanted to know if it’s possible to replace the Spring Cloud Config Server with Azure App Configuration without changing the client services. This post will explain every step I took to build a first version of an Azure Spring Boot Config Server.

Starting point of this project was my previous post where I created a basic Spring Boot web application with feature flags. The pom.xml stayed pretty much the same. What’s different is everything else. Here’s an illustration about what I wanted to achieve. Instead of configuring a client service with -Dspring.cloud.config.uri=<old_SPRING_CLOUD_CONFIG_SERVER>, I wanted to replace just the address: -Dspring.cloud.config.uri=<new_AZURE_CONFIG_SERVER>.

Motivation

The challenge with Spring Cloud Config Server is its dependency to a Git repository which tend to have either no SLA, or an SLA of three nines which would allow for 8h 45m 56s downtime in a year. We experienced lots of problems related to the Java Config Repo which prevented our Spring Cloud Config Server to start which further prevented our services to start. In case of an incident a pretty awful situation.

Replacing Spring Cloud Config Server with Azure App ConfigurationReplacing Spring Cloud Config Server with Azure App Configuration

Spring Cloud Config Server - Simplified

The interesting part is how Spring Cloud Config Server serves configurations, and what endpoints it has. To find out, I took a look at what requests the clients send to the config server: http://<old_SPRING_CLOUD_CONFIG_SERVER>/<CONTEXT_PATH>/<APPLICATION>/<PROFILE>/<LABEL>/FILE.

  • Application represents the folder within the Java Configuration Repo.
  • Profile is the the profile the service - Config Server or Client Service - was started with.
  • Label is a Git-Hash, tag or branch.
  • File is the filename with the extension that you’d like to retrieve.

All these information must somehow be captured in an Azure App Configuration instance, normally. In my case, the profile is the same as the label, so I ignored this information for now.

Configuration

The new Azure Config Server can connect to one or many Azure App Configuration instances. Each team or application can have its own instance, cross service configurations could be in a dedicated Azure App Configuration instance. I will configure just one instance as I want to import all configurations of all of our Java Spring Services and all cross service configurations at once. his project is a proof of concept after all.

spring.cloud.azure.appconfiguration.stores[0].connection-string= ${APP_CONFIGURATION_CONNECTION_STRING}
spring.cloud.azure.appconfiguration.stores[0].label=test
spring.cloud.azure.appconfiguration.cache-expiration=1s

Configurations in Azure App Configuration can be labeled with i.e. the name of the environment dev, test or production, or anything else. The new Azure Config Server will first run in the test environment. I set cache-expiration to one second to see changes faster, default is 30 seconds. I really don’t want to wait so long while testing and playing around.

Model

The name of the one and only model is ConfigApiProperties. It has two members:

// Configurations from Azure App Configuration
private Map<String, String> config;

// The filename that was requested
private String file;

I ignored profile and label for now as I would start a new instance of the new Azure Config Server for every environment anyway. This makes sense where you have dedicated clusters for each and every environment.

Controller

The controller defines the endpoint(s) the Azure Config Server needs to listen to. As I said previously, this is a first version, a proof of concept if you will. It accepts all profiles at the moment. All configurations will be labeled with test but should ideally be set automatically from the bootstrap configuration spring.cloud.azure.appconfiguration.stores[0].label, something for later to implement - focusing on the core first.

@GetMapping(value = { "/{application}/*/test/{file}" }, produces = MediaType.TEXT_PLAIN_VALUE)
public String getMessage(@PathVariable String application, @PathVariable String file) {
    // The core of the code you would put here will
    // convert the HashMap ConfigApiProperties.config
    // into one String with new lines so that the
    // returning String looks like a real properties file.
}

Configuration Prefix in Azure App Configuration

Azure App Configuration let us define entries with different prefixes and labels. As I will import all configurations of all applications that have each many files defined. It probably is bad practice to even consider putting it all into one instance. I do it anyway. I will use the prefix to distinguish applications and files: /application/config.<APPLICATION>.<FILE>.. The default deliminator is a dot ..

  • /application/ is the prefix that spring-cloud-azure-appconfiguration-config-web will prefix by default. This can’t be changed unless you patch the class.
  • config is the member of the ConfigApiProperties-model.
  • <APPLICATION> is the foldername of the requesting service within the Java Configuration Repo.
  • <FILE> is the filename being requested.

Next Steps

The complete code - that I can’t share for now - has some flaws and performance issues if I can say that. I mean the Spring Cloud Config Server checks out an entire repository which can take minutes. The new Azure Config Service will read all configurations and filter then what’s get returned to the requesting service. Also is profile information missing at the moment. If you would like to get some more details about the code, please drop me a message.

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

Latest Stories

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

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 implem...

May 16, 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

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

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

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

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

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

Azure API Management with Terraform

Terraform is a popular tool for managing infrastructure resources. I counted about 120 supported providers. Azure is one of them. In this...

Apr 04, 2020

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

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020

Latest Stories

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

Using Feature Flags with Azure App Configuration

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 implem...

May 16, 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

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

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

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

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

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

Azure API Management with Terraform

Azure API Management with Terraform

Terraform is a popular tool for managing infrastructure resources. I counted about 120 supported providers. Azure is one of them. In this...

Apr 04, 2020

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

Serving Website Images from Azure CDN with SSL

Serving Website Images from Azure CDN with SSL

In this post I will show you step by step how to serve images on a website from Azure CDN with SSL enabled. My blog has a couple of Azure...

Apr 25, 2020