Since the introduction of the Jenkins Declarative Pipeline syntax (as opposed to the Scripted Pipeline syntax) the concept of a shared library has become more important as we are otherwise restricted to the sections of the pipeline model. So we’ll make a basic set-up with Continue reading
We can use Spring Boot Actuator to add endpoints to our application that can expose information about our application. For example we can request the
/env endpoint to see which Spring environment properties are available. Or use
/configprops to see the values of properties defined using
@ConfigurationProperties. Sensitive information like passwords and keys are replaced with
******. Spring Boot Actuator has a list of properties that have sensitive information and therefore should be replaced with
******. The default list of keys that have their value hidden is defined as
password,secret,key,token,.*credentials.*,vcap_services. A value is either what the property name ends with or a regular expression. We can define our own list of property names from which the values should be hidden or sanitized and replaced with
******. We define the key we want to be hidden using the application properties
When we write a feature method in our Spock specification to test our class we might run into long running methods that are invoked. We can specify a maximum time we want to wait for a method. If the time spent by the method is more than the maximum time our feature method must fail. Spock has the
@Timeout annotation to define this. We can apply the annotation to our specification or to feature methods in the specification. We specify the timeout value as argument for the
@Timeout annotation. Seconds are the default time unit that is used. If we want to specify a different time unit we can use the annotation argument
unit and use constants from
java.util.concurrent.TimeUnit to set a value.
To ignore feature methods in our Spock specification we can use the annotation
@Ignore. Any feature method or specification with this annotation is not invoked when we run a specification. With the annotation
@IgnoreRest we indicate that feature methods that do not have this annotation must be ignored. So any method with the annotation is invoked, but the ones without aren’t. This annotation can only be applied to methods and not to a specification class.
On my current project we use Java 8, Spring 4.3 and Tomcat 7.0 as application server. After the scheduling functionality was added to the project the application server did not shut down any more, it hung till the end of time.
I like to use the default Java implementations when possible so the configured scheduler was the
In a modern service landscape, especially when using containers, you are probably using something like the ELK stack (Elasticsearch, Logstash, Kibana) to flow all the logging into.
But how to find from all those loglines what caused the nasty bug after a innocent buttonpress?
One of the easy answers to this is what’s called a correlation id – basically a unique number assigned to that buttonpress which gets carried around between the services and added to every logline.
Sounds good you say? it is so let’s see how to do this.
When we want to transform a
Promise value we can use the
flatMap methods. There are also variants to this methods that will only transform a value when a given predicate is true:
flatMapIf. We provide a predicate and function to the methods. If the predicate is true the function is invoked, otherwise the function is not invoked and the promised value is returned as is.
Promise class has a lot of methods. One of the methods is the
time method. We can invoke this method an a
Promise instance. The method creates a
Duration object that we can use inside the method. The duration is the time taken from when the promise is subscribed to to when the result is available. The promise value is not changed, so we can add the
time method at any position of a method chain for the
To run external Groovy scripts in our Java or Groovy application is easy to do. For example we can use
GroovyShell to evaluate Groovy code in our applications. If our script contains print methods like
println we can redirect the output of these methods. The
Script class, which is a base class to run script code, has an implementation for the
println methods. The implementation of the method is to look for a property
out, either as part of a
Script subclass or in the binding added to a
Script class. If the property
out is available than all calls to
println methods are delegated to the object assigned to the
out property. When we use a
PrintWriter instance we have such an object, but we could also write our own class with an implementation for the
out property the fallback is to print on