Home About News Products Blog

How to test and validate configuration changes in Production (Using Varnish Cache)


#1

Testing configuration changes is an important part of good change / release management. Being able to have flexible options for testing enables faster development and release cycles.

There are a number of ways to test configuration changes in Production without impacting all users.

  1. Use section.io Developer PoP - This enables a single user to see changes on their PC ahead of production release - https://www.section.io/docs/tutorials/developer-workflow/

  2. Use a “Canary” release strategy to only enable the feature for a limited subset of actual users.

Canary Release Strategy

The following provides ways to only enable a new feature or code change for a limited subset of users in Varnish Cache.

The best approach is the wrap the whole new configuration in an IF block that checks one or more of:

Here is a sample VCL snippet to look for one of the above options and execute the code in the statement only for that subset of users:

sub vcl_recv {
  
  	#Check for one (or more) of the following Canary signals
	if(req.http.Your-Custom-Header || req.http.cookie ~ "customcookiename" || req.http.True-Client-IP ~ "4.5.6.7"){
      
    	#New Feature Custom Code goes here

    }
  
}

This code can be extended to run in any VCL sub or simple set a unique value in vcl_recv that is then looked for in all other code areas to see if the Canary is active.

An additional note when caching is that you may need to split the cache by users getting the new feature and users that dont. This way changes - to say image optimisation for example - are not visible to all users.
The below code snippet extends the Canary code to also split the cache by the feature:
sub vcl_recv {

  	#Check for one (or more) of the following Canary signals
	if(req.http.Your-Custom-Header || req.http.cookie ~ "customcookiename" || req.http.True-Client-IP ~ "4.5.6.7"){
      
    	#New Feature Custom Code goes here
  
  		#Set a custom header indicating feature is active
  		set req.http.Canary-Feature1 = "true";
    }
  
}

sub vcl_hash {
	hash_data(req.http.Canary-Feature1); 
}