These are chat archives for spring-cloud/spring-cloud

14th
Apr 2016
Johannes Edmeier
@joshiste
Apr 14 2016 05:20
@spencergibb :+1: thanks!
Felipe Santos
@felipemsantos
Apr 14 2016 14:01

Hi guys, I'm facing a design issue on an API client using Feign. I have the following situation:

On my "api-server-module":

  1. I have a CrudApi<T> (where all @RequestMappings are declared, and T is just a serializable "entity") and a abstract class GenericCrudApi<T> that generalizes the implementation of CrudApi<T>;
  2. For each REST resource I have an interface that extends CrudApi and extends GenericCrudApi, for example:
public interface UserApi extends CrudApi<User> {
...
}

public interface ProductApi extends CrudApi<User> {
...
}

@RestController
@RequestMapping("/users")
public class UserResource extends GenericCrudApi<User> implements UserApi {
...
} 

@RestController
@RequestMapping("/products")
public class ProductResource extends GenericCrudApi<Product> implements ProductApi {
...
}

So I'm trying to figure out how to create a @FeignClient("api-server-module") that maps the both REST resources, something like:

@FeignClient("api-server-module")
public interface ApiClient {

   UserApi userApi();

   ProductApi productApi();

}

Is it possible? One of my goals is to use the interface inheritance to implement the controller and the client.

Spencer Gibb
@spencergibb
Apr 14 2016 14:14
@felipemsantos no, you need a feign client for each.
You could certainly have a normal spring bean that aggregates the clients.
Felipe Santos
@felipemsantos
Apr 14 2016 14:17
hum, yeah the spring bean to aggregates is what i'm doing right now, and how should I map the resources (something like @FeignClient(url="http://api-server-module/user"))?
the api-server-module is my spring.application.name and is registered on eureka
Spencer Gibb
@spencergibb
Apr 14 2016 14:19
Just name=api-server-module
With quotes
Felipe Santos
@felipemsantos
Apr 14 2016 17:57
Thanks @ps
ops
thank you @spencergibb but I fall on "Only single inheritance supported" issue
i'll review my implementation strategy
anyway thanks again
Pedro Alvarado
@PedroAlvarado
Apr 14 2016 19:44
@dsyer I'm attempting to export all metrics(public+servo+other metrics) available in a spring cloud app to redis. I've added a MetricWriter qualified with @ExportMetricWriter. However, It seems that the metric exporter is not being configured. Per the documentation, I think I need to add a MetricReader, howoever, I'm not entirely sure how to go about adding a reader that exports all the app metrics. I'd be great if you can provide some insight as to how to get this working.
Dave Syer
@dsyer
Apr 14 2016 20:02
@ExportMetricWriter is enough to get something out
If that's not working you can postpone the reader side until you have solved the writer problem
There's a redis sample you know in Spring Boot
Pedro Alvarado
@PedroAlvarado
Apr 14 2016 20:09
The writer is being properly configured. I'm using exactly what is provided on the boot metrics documentation. The issue seems to be that the MetricsExporter is not being auto configured because there are no reader and no MetricCopyExporter already available in the context.
@Bean
@ConditionalOnMissingBean(name = "metricWritersMetricExporter")
public SchedulingConfigurer metricWritersMetricExporter() {
    Map<String, GaugeWriter> writers = new HashMap<String, GaugeWriter>();
    MetricReader reader = this.endpointReader;
    if (reader == null && !CollectionUtils.isEmpty(this.readers)) {
        reader = new CompositeMetricReader(
                this.readers.toArray(new MetricReader[this.readers.size()]));
    }
    if (reader == null && this.exporters.isEmpty()) {
        return new NoOpSchedulingConfigurer();
    }
    MetricExporters exporters = new MetricExporters(this.properties);
    if (reader != null) {
        writers.putAll(this.writers);
        exporters.setReader(reader);
        exporters.setWriters(writers);
    }
    exporters.setExporters(this.exporters);
    return exporters;
}
The bean returned from that bean method is a NoOpSchedulingConfigurer. The code reads as if we need a MetricReader in order for the MetricExporters to actually create a MetricCopyExporter.
Dave Syer
@dsyer
Apr 14 2016 20:41
You must have managed to disable the actuator metrics somehow
Pedro Alvarado
@PedroAlvarado
Apr 14 2016 20:46
The "/metrics"endpoint is operational in my current configuration.
Dave Syer
@dsyer
Apr 14 2016 20:46
@ExportMetricReader is only used once in Spring Boot (to expose the metrics from the CounterService and GaugeService)
If you don't have those
there won't be one
Maybe you have Dropwizard metrics on the classpath?
Pedro Alvarado
@PedroAlvarado
Apr 14 2016 20:56
I don't have dropwizard however servo is in the classpath.
Pedro Alvarado
@PedroAlvarado
Apr 14 2016 21:05
@ExportMetricReader is used only by LegacyMetricRepositoryConfiguration and FastMetricServicesConfiguration out of the box. Both are not being configured because ServoMetricServices is being configured automatically. This means that by default there is no @ExportMetricReader being configured when spring-boot and spring-cloud are used together.
Marcos Barbero
@marcosbarbero
Apr 14 2016 22:25
@dsyer this commit spring-cloud/spring-cloud-netflix@d0841f7 will be available on Brixon.RC2?
Dave Syer
@dsyer
Apr 14 2016 22:26
@marcosbarbero is it in master?
If so it will be in RC2 (we always release the latest version from master)
Marcos Barbero
@marcosbarbero
Apr 14 2016 22:27
Great, just checked and yes, it is in master.
Thanks for your time. :)
Dave Syer
@dsyer
Apr 14 2016 22:27
@PedroAlvarado there you are then. And it should be obvious how to fix it.
David Welch
@dwelch2344
Apr 14 2016 22:44
Just bringing up the subject again: encrypted properties in Spring Cloud (Consul FWIW) apps. Thoughts?
Spencer Gibb
@spencergibb
Apr 14 2016 22:46
@dwelch2344 two thoughts, decrypt in the client or use something like hashicorps, vault https://github.com/spencergibb/spring-cloud-vault-config