From 58220dcb1c692d5c356622f89dbee391791ce34b Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 30 Nov 2020 07:39:19 +0100 Subject: [PATCH] Remove entity type as it is no longer supported by Elasticsearch Closes gh-1154 --- .../stat/ProjectGenerationStatPublisher.java | 4 +-- .../actuate/stat/StatsProperties.java | 15 +--------- ...itional-spring-configuration-metadata.json | 13 ++++++++ .../ProjectGenerationStatPublisherTests.java | 30 +++++++++---------- 4 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 initializr-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json diff --git a/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisher.java b/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisher.java index 098f9662..841b022a 100644 --- a/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisher.java +++ b/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisher.java @@ -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); } diff --git a/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/StatsProperties.java b/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/StatsProperties.java index 1329e794..76e62f32 100644 --- a/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/StatsProperties.java +++ b/initializr-actuator/src/main/java/io/spring/initializr/actuate/stat/StatsProperties.java @@ -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; } diff --git a/initializr-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/initializr-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json new file mode 100644 index 00000000..8cf85d38 --- /dev/null +++ b/initializr-actuator/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -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" + } + } + ] +} \ No newline at end of file diff --git a/initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisherTests.java b/initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisherTests.java index bdf754ae..f633d8de 100755 --- a/initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisherTests.java +++ b/initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisherTests.java @@ -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);