Merge pull request #38 from spring-cloud/37-wavefront

Wavefront Support
This commit is contained in:
E Casey
2020-05-15 16:53:20 -04:00
committed by GitHub
6 changed files with 132 additions and 3 deletions

View File

@@ -202,6 +202,16 @@ Disable Property: `org.springframework.cloud.bindings.boot.sqlserver.enable`
| `spring.datasource.url` | `jdbc:sqlserver://{secret/host}:{secret/port}/{secret/database}`
| `spring.datasource.username` | `{secret/username}`
### Wavefront
Kind: `Wavefront`
Disable Property: `org.springframework.cloud.bindings.boot.wavefront.enable`
| Property | Value
| -------- | ------------------
| `management.metrics.export.wavefront.api-token` | `{secret/api-token}`
| `management.metrics.export.wavefront.uri` | `{secret/uri}`
## License
This buildpack is released under version 2.0 of the [Apache License][a].

View File

@@ -134,7 +134,7 @@ public final class Bindings {
return bindings.stream()
.filter(binding ->
(kind == null || binding.getKind().equalsIgnoreCase(kind)) &&
(provider == null) || binding.getProvider().equalsIgnoreCase(provider))
(provider == null || binding.getProvider().equalsIgnoreCase(provider)))
.collect(Collectors.toList());
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
import static org.springframework.cloud.bindings.boot.Guards.isKindEnabled;
/**
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
*/
public final class WavefrontBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
/**
* The {@link Binding} kind that this processor is interested in: {@value}.
**/
public static final String KIND = "Wavefront";
@Override
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}
bindings.filterBindings(KIND).forEach(binding -> {
MapMapper map = new MapMapper(binding.getSecret(), properties);
map.from("api-token").to("management.metrics.export.wavefront.api-token");
map.from("uri").to("management.metrics.export.wavefront.uri");
});
}
}

View File

@@ -15,4 +15,5 @@ org.springframework.cloud.bindings.boot.BindingsPropertiesProcessor=\
org.springframework.cloud.bindings.boot.PostgreSqlBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.RabbitMqBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.RedisBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.SqlServerBindingsPropertiesProcessor
org.springframework.cloud.bindings.boot.SqlServerBindingsPropertiesProcessor, \
org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor

View File

@@ -98,7 +98,7 @@ final class BindingSpecificEnvironmentPostProcessorTest {
@Test
@DisplayName("included implementations are registered")
void includedImplementations() {
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(13);
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(14);
}
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.bindings.boot.WavefrontBindingsPropertiesProcessor.KIND;
@DisplayName("Wavefront BindingsPropertiesProcessor")
final class WavefrontPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("api-token", "test-api-token")
.withEntry("uri", "test-uri")
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new WavefrontBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("management.metrics.export.wavefront.api-token", "test-api-token")
.containsEntry("management.metrics.export.wavefront.uri", "test-uri");
}
@Test
@DisplayName("can be disabled")
void disabled() {
environment.setProperty("org.springframework.cloud.bindings.boot.wavefront.enable", "false");
new WavefrontBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}
}