Remove entity type as it is no longer supported by Elasticsearch

Closes gh-1154
This commit is contained in:
Stephane Nicoll 2020-11-30 07:39:19 +01:00
parent f94566d066
commit 58220dcb1c
4 changed files with 31 additions and 31 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -129,7 +129,7 @@ public class ProjectGenerationStatPublisher {
}
private static URI determineEntityUrl(Elastic elastic) {
String entityUrl = elastic.getUri() + "/" + elastic.getIndexName() + "/" + elastic.getEntityName();
String entityUrl = elastic.getUri() + "/" + elastic.getIndexName() + "/_doc/";
try {
return new URI(entityUrl);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -60,11 +60,6 @@ public class StatsProperties {
*/
private String indexName = "initializr";
/**
* Name of the entity to use to publish stats.
*/
private String entityName = "request";
/**
* Number of attempts before giving up.
*/
@ -94,14 +89,6 @@ public class StatsProperties {
this.indexName = indexName;
}
public String getEntityName() {
return this.entityName;
}
public void setEntityName(String entityName) {
this.entityName = entityName;
}
public int getMaxAttempts() {
return this.maxAttempts;
}

View File

@ -0,0 +1,13 @@
{
"properties": [
{
"name": "initializr.stats.elastic.entity-name",
"type": "java.lang.String",
"description": "Name of the entity to use to publish stats.",
"deprecation": {
"reason": "Elasticsearch does no longer support mapping types.",
"level": "error"
}
}
]
}

View File

@ -93,7 +93,7 @@ class ProjectGenerationStatPublisherTests {
properties.getElastic().setUsername("foo");
properties.getElastic().setPassword("bar");
configureService(properties);
testAuthorization("https://example.com/elastic/initializr/request",
testAuthorization("https://example.com/elastic/initializr/_doc/",
header("Authorization", "Basic Zm9vOmJhcg=="));
}
@ -102,7 +102,7 @@ class ProjectGenerationStatPublisherTests {
StatsProperties properties = new StatsProperties();
properties.getElastic().setUri("https://elastic:secret@es.example.com");
configureService(properties);
testAuthorization("https://es.example.com/initializr/request",
testAuthorization("https://es.example.com/initializr/_doc/",
header("Authorization", "Basic ZWxhc3RpYzpzZWNyZXQ="));
}
@ -113,7 +113,7 @@ class ProjectGenerationStatPublisherTests {
properties.getElastic().setUsername("another");
properties.getElastic().setPassword("ignored-secret");
configureService(properties);
testAuthorization("https://es.example.com/initializr/request",
testAuthorization("https://es.example.com/initializr/_doc/",
header("Authorization", "Basic ZWxhc3RpYzpzZWNyZXQ="));
}
@ -122,7 +122,7 @@ class ProjectGenerationStatPublisherTests {
StatsProperties properties = new StatsProperties();
properties.getElastic().setUri("https://example.com/test/");
configureService(properties);
testAuthorization("https://example.com/test/initializr/request",
testAuthorization("https://example.com/test/initializr/_doc/",
(request) -> assertThat(request.getHeaders().containsKey("Authorization")).isFalse());
}
@ -152,7 +152,7 @@ class ProjectGenerationStatPublisherTests {
request.getParameters().put("cf-connecting-ip", "10.0.0.42");
request.getParameters().put("cf-ipcountry", "BE");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST)).andExpect(json("stat/request-simple.json", event.getTimestamp()))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON));
@ -171,7 +171,7 @@ class ProjectGenerationStatPublisherTests {
request.setDependencies(Arrays.asList("web", "data-jpa"));
request.setLanguage("java");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST)).andExpect(json("stat/request-no-client.json", event.getTimestamp()))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON));
@ -190,7 +190,7 @@ class ProjectGenerationStatPublisherTests {
request.setDependencies(Arrays.asList("web", "data-jpa"));
request.setLanguage("java");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST))
.andExpect(json("stat/request-invalid-type.json", event.getTimestamp()))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
@ -210,7 +210,7 @@ class ProjectGenerationStatPublisherTests {
request.setDependencies(Arrays.asList("web", "data-jpa"));
request.setLanguage("c");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST))
.andExpect(json("stat/request-invalid-language.json", event.getTimestamp()))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
@ -231,7 +231,7 @@ class ProjectGenerationStatPublisherTests {
request.setLanguage("java");
request.setJavaVersion("1.2");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST))
.andExpect(json("stat/request-invalid-java-version.json", event.getTimestamp()))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
@ -251,7 +251,7 @@ class ProjectGenerationStatPublisherTests {
request.setDependencies(Arrays.asList("invalid-2", "web", "invalid-1"));
request.setLanguage("java");
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST))
.andExpect(json("stat/request-invalid-dependencies.json", event.getTimestamp()))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
@ -265,13 +265,13 @@ class ProjectGenerationStatPublisherTests {
void recoverFromError() {
ProjectRequest request = createProjectRequest();
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.CREATED).body(mockResponse(UUID.randomUUID().toString(), true))
.contentType(MediaType.APPLICATION_JSON));
@ -286,10 +286,10 @@ class ProjectGenerationStatPublisherTests {
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request, this.metadata);
this.retryTemplate.setRetryPolicy(new SimpleRetryPolicy(2, Collections.singletonMap(Exception.class, true)));
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/request"))
this.mockServer.expect(requestTo("https://example.com/elastic/initializr/_doc/"))
.andExpect(method(HttpMethod.POST)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
this.statPublisher.handleEvent(event);