How to override gatling.conf for graphite configuration? - maven

I downloaded gatling as a maven dependency and now I'm looking for how to override the gatling.conf file to configure the connection between gatling and graphite.
So I created a gatling.conf file like that :
data {
writers = [console, file, graphite] # The list of DataWriters to which Gatling write simulation data (currently supported : console, file, graphite, jdbc)
reader = file # The DataReader used by the charting engine for reading simulation results
console {
light = false # When set to true, displays a light version without detailed request stats
}
file {
bufferSize = 8192 # FileDataWriter's internal data buffer size, in bytes
}
leak {
noActivityTimeout = 30 # Period, in seconds, for which Gatling may have no activity before considering a leak may be happening
}
graphite {
light = false # only send the all* stats
host = "mygraphite.host.com" # The host where the Carbon server is located
port = 1010 # The port to which the Carbon server listens to (2003 is default for plaintext, 2004 is default for pickle)
protocol = "tcp" # The protocol used to send data to Carbon (currently supported : "tcp", "udp")
rootPathPrefix = "gatling" # The common prefix of all metrics sent to Graphite
bufferSize = 8192 # GraphiteDataWriter's internal data buffer size, in bytes
writeInterval = 1 # GraphiteDataWriter's write interval, in seconds
}
}
Inside my src/main/resources/conf/gatling.conf
Here's my pom.xml :
<build>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-plugin.version}</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<configFolder>src/main/resources/conf/</configFolder>
<!-- Default values -->
<!--<configFolder>src/test/resources</configFolder-->
<dataFolder>src/main/resources/data</dataFolder>
<resultsFolder>target/gatling/results</resultsFolder>
<!--<!–<requestBodiesFolder>src/test/resources/request-bodies</requestBodiesFolder>-->
<simulationsFolder>src/main/scala</simulationsFolder>
<simulationClass>my.awesomeCompany.scenarios.Scenarios</simulationClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
What I'm doing wrong, there's an other way to do that with a config file ? Or I'll have to override all the options with jvm args ?
Cheers.

You're missing the configuration root, gatling. Therefore, your values overrides nothing. Wrap your data { … } block in a gatling { … } block and it'll work.

Related

OpenApi generator generates spring boot 2 server controller interface with incorrect(?) Flux / Mono response types

I'm trying to generate controller interface with Flux / Mono types(I'm doing refactor to WebFlux).
Here is my openapi spec part:
/api/courses:
get:
tags:
- RestCourse
summary: Provides all courses
operationId: getAll
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ApiCourse'
Part of pom.xml:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>6.0.1</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi.yaml</inputSpec>
<generatorName>spring</generatorName>
<!--<templateDirectory>${project.basedir}/templates</templateDirectory>-->
<configOptions>
<dateLibrary>java8</dateLibrary>
<!--<useSpringController>true</useSpringController>-->
<interfaceOnly>true</interfaceOnly>
<sourceFolder>src/java/main</sourceFolder>
<modelPackage>spring.learn.api.model</modelPackage>
<apiPackage>spring.learn.api.controller</apiPackage>
<useTags>true</useTags>
<unhandledException>true</unhandledException>
<openApiNullable>false</openApiNullable>
<reactive>true</reactive>
<!--<library>spring-boot</library>-->
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Generated result is:
default Mono<ResponseEntity<Flux<ApiCourse>>> getAll(...
But i think should be:
default Flux<ResponseEntity<ApiCourse>> getAll(...
Or I'm wrong?
These types are correct, I had the same question. Here's what the documentation has to say about it:
Mono<ResponseEntity<Mono<T>>> or Mono<ResponseEntity<Flux<T>>> are yet another possible, albeit less common alternative. They provide the response status and headers asynchronously first and then the response body, also asynchronously, second.

Maven Exec Plugin : Can't write a command output to a file

I want to use Maven Exec Plugin in order to write a command output to a file,
I was only able to do it by running a shell command that the plugin is invoking.
This is the shell script:
git rev-parse --abbrev-ref HEAD > branch.txt
This is my pom.xml:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<inherited>false</inherited>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-instrument</artifactId>
<version>5.3.21</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>gitbranch.sh</executable>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
</plugin>
When trying to run it as a command and not using a script , I can't get to be written into a file:
<configuration>
<executable>git</executable>
<outputFile>branching.txt</outputFile>
<arguments>
<argument>rev-parse</argument>
<argument>--abbrev-ref</argument>
<argument>HEAD</argument>
</arguments>
<workingDirectory>${basedir}</workingDirectory>
</configuration>
I also tried to run echo "something" > file.txt using this plugin, but nothing is writing anything in to a file.
This may not directly answer your question but I use maven git commit id plugin to do the same thing you want to do. I have:
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<useNativeGit>true</useNativeGit>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssXXX</dateFormat>
<dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
</plugin>
in my build/plugins section of my pom.xml. When I run this I get the file named git.properties generated in my target/classes directory that contains:
#Generated by Git-Commit-Id-Plugin
#Wed Jul 06 11:51:45 MDT 2022
git.branch=feature/test-branch
git.build.host=bluerock
git.build.time=2022-07-06T11\:51\:45-06\:00
git.build.user.email=
git.build.user.name=
git.build.version=1.0
git.closest.tag.commit.count=
git.closest.tag.name=
git.commit.id=c991301b1a88e6cd138d347c46e3479d34b6f24d
git.commit.id.abbrev=c991301
git.commit.id.describe=c991301
git.commit.id.describe-short=c991301
git.commit.message.full=cleaned up a bit
git.commit.message.short=cleaned up a bit
git.commit.time=2020-09-29T11\:48\:58-06\:00
git.commit.user.email=myemail#example.tld
git.commit.user.name=First Last
git.dirty=false
git.remote.origin.url=<the git url>
git.tags=
git.total.commit.count=4
Then, in my code base I have:
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class VersionInfo {
public String getVersionString() {
try {
Properties properties = getGitProperties();
boolean isDirty = false;
String gitDirty = properties.getProperty( "git.dirty" );
if( gitDirty != null )
isDirty = Boolean.parseBoolean(gitDirty);
return "built \"" + properties.getProperty("git.build.time") +
"\" in branch \"" + properties.getProperty("git.branch") +
"\" with short commit id \"" + properties.getProperty("git.commit.id.describe-short") + "\"" +
", isDirty is " + isDirty +
" remote url is \"" + properties.getProperty("git.remote.origin.url") + "\"";
}
catch( IOException ioe ) {
return( "can't locate git.properties on the class path");
}
}
private Properties getGitProperties() throws IOException {
Properties properties = new Properties();
try (InputStream inputStream = this.getClass().getResourceAsStream("/git.properties")) {
if (inputStream == null)
throw new IOException("Can't locate properties file to generate version info");
properties.load(inputStream);
return properties;
}
}
}
This allows me to print out information about the git environment as part of a startup string or do what you want with it. Again

OpenApi generator not generating the "description" tag

Given the below (snippet) of my spec
paths:
/login:
post:
summary: "Method to login to obtain a JWT token"
description: "Some description"
operationId: login
tags:
- login
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Credentials"
application/xml:
schema:
$ref: "#/components/schemas/Credentials"
and using the maven plugin with following config
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.4.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/spec.yaml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.company.api</apiPackage>
<modelPackage>com.company.model</modelPackage>
<modelNameSuffix>DTO</modelNameSuffix>
<typeMappings>
<typeMapping>Pageable=org.springframework.data.domain.Pageable</typeMapping>
<typeMapping>OffsetDateTime=LocalDateTime</typeMapping>
</typeMappings>
<importMappings>
<importMapping>java.time.OffsetDateTime=java.time.LocalDateTime</importMapping>
</importMappings>
<configOptions>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
The generated code looks like (cleaned up a bit to the relevant parts)
/**
* POST /login : Method to login to obtain a JWT token
* Some description
*
* #param credentialsDTO (optional)
* #return Login success (status code 200)
* or Unexpected error (status code 500)
*/
#Operation(
operationId = "login",
summary = "Method to login to obtain a JWT token",
tags = { "login" }
)
#RequestMapping(
method = RequestMethod.POST,
value = "/login",
produces = { "application/json", "application/xml" },
consumes = { "application/json", "application/xml" }
)
ResponseEntity<JWTTokenDTO> login(...)
);
As shown, the 'description' from the spec is used to generate the JavaDoc, but in fact I'm expecting it to generate the 'description' attribute on #Operation tag.
I've searched for solutions, but I could not find the solution.
How can I correct this ?
Thanks in advance.
Unfortunately that can not be done simply by adjusting plugin configuration. Instead one must modify templates.
In this specific case it can be done as follows:
Fetch original template from: https://github.com/OpenAPITools/openapi-generator/blob/v5.4.0/modules/openapi-generator/src/main/resources/JavaSpring/api.mustache
Store it to src/main/resources/openapi/templates/api.mustache
Add templateDirectory to plugin configuration:
<configuration>
...
<templateDirectory>${project.basedir}/src/main/resources/openapi/templates</templateDirectory>
</configuration>
Locate part of api.mustache that is template for #Operation from api.mustache (starts from line 130)
#Operation(
operationId = "{{{operationId}}}",
{{#summary}}
summary = "{{{.}}}",
{{/summary}}
Add description attribute there (value comes from notes):
#Operation(
operationId = "{{{operationId}}}",
{{#summary}}
summary = "{{{.}}}",
{{/summary}}
{{#notes}}
description = "{{{.}}}",
{{/notes}}
More information about templating is available here: Using Templates

Failed test in jenkins maven

i have a problem with maven in jenkins. When I building application using maven in jenkis, I got error:
[ERROR] Failures:
[ERROR] MessageResourceIT.Should add Message to Room:49 Condition not satisfied:
response.getStatusCode() == HttpStatus.CREATED
| | | |
| 403 FORBIDDEN false 201 CREATED
It looks like a normal failed test, but when I building application in my computer, test is correct.
My test:
def "Should add Message to Room"() {
given:
Room room = roomHelper.room()
participantHelper.participant(room.id, user.id)
AddMessageRequest request = messageHelper.addMessageRequest()
String url = UriComponentsBuilder.fromPath('/room/{roomId}/message')
.buildAndExpand(room.id)
HttpEntity payload = new HttpEntity<>(request, userHeaders)
when:
ResponseEntity<MessageResponse> response = restTemplate.exchange(url, HttpMethod.POST, payload, MessageResponse.class)
then:
response.getStatusCode() == HttpStatus.CREATED
response.body
MessageResponse messageResponse = response.body
messageResponse.content == request.content
}
my setup:
def setup() {
String userLogin = 'test'
String userPassword = 'test'
user = userHelper.user(userPassword, userLogin)
userHeaders = securityHelper.securityHeader(userLogin, userPassword)
}
It's look as jenkins running tests asynchronously and another test removed users when this test is running.
I using maven-failsafe-plugin:
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<skipITs>false</skipITs>
<includes>
<include>%regex[.*IT.*]</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
Anyone have an idea what can happen and how to fix it?

Maven yuicompressor-plugin generates minified js encoded in ANSI

I'm trying to minify a group of js files with maven's yuicompressor-plugin. One of this files has to be encoded in UTF-8 because it has special characters:
String.prototype.removeTicks = function (/*thisArg */) {
var __r =
{
'À':'A','Á':'A','Â':'A','Ã':'A','Ä':'A','Å':'A','Æ':'E',
'È':'E','É':'E','Ê':'E','Ë':'E',
'Ì':'I','Í':'I','Î':'I',
'Ò':'O','Ó':'O','Ô':'O','Ö':'O',
'Ù':'U','Ú':'U','Û':'U','Ü':'U',
'N':'N'
};
return this.replace(/[ÀÁÂÃÄÅÆÈÉÊËÌÍÎÒÓÔÖÙÚÛÜÑ]/gi, function(m)
{
var ret = __r[m.toUpperCase()];
if (ret && m === m.toLowerCase())
ret = ret.toLowerCase();
return ret;
});
};
But, when I run the compressor the output file is encoded in ANSI and all special characters are broken. I tried to configure the charset encoding in the plugin configuration and change all files to UTF-8, but none of this work. Here is the pom extract:
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>yuicompressor-maven-plugin</artifactId>
<version>1.3.0</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>compress</goal>
</goals>
</execution>
</executions>
<configuration>
<nosuffix>true</nosuffix>
<nocompress>true</nocompress>
<sourceDirectory>${basedir}/../../public</sourceDirectory>
<outputDirectory>${basedir}/target</outputDirectory>
<encoding>UTF-8</encoding>
<aggregations>
<aggregation>
<removeIncluded>true</removeIncluded>
<output>${basedir}/target/${project.build.finalName}/js/custom.js</output>
<inputDir>${basedir}/target/js</inputDir>
<includes>
<include>util/string/string.js</include>
<include>...</include>
</includes>
</aggregation>
</aggregations>
</configuration>
</plugin>
Anyone ever had this problem and solved it?
Make sure you placed the correct charset in tag for the script you are injecting. This might work.
<script src="foo.js" type="text/javascript" charset="utf-8"></script>

Resources