Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Why PCF is the best platform for Spring Boot

6,204 views

Published on

Why PCF is the best platform for Spring Boot

Published in: Technology
  • Dating for everyone is here: ❶❶❶ http://bit.ly/2F7hN3u ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sex in your area is here: ❶❶❶ http://bit.ly/2F7hN3u ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • How to Manifest Anything with the Law of Attraction ●●● http://t.cn/AiuvUMl2
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The Surprising Reason 11:11 Keeps Appearing. Free report reveals hidden messages from the Universe to unlock success, wealth... even true love. Claim your copy and reveal your messages now! ◆◆◆ https://tinyurl.com/y6pnne55
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hello! Get Your Professional Job-Winning Resume Here - Check our website! https://vk.cc/818RFv
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Why PCF is the best platform for Spring Boot

  1. 1. 1 Why PCF is the best platform for Spring Boot 2017-07-20 Toshiaki Maki (@making)
  2. 2. Who am I ? 2 Toshiaki Maki (@making) https://blog.ik.am Sr. Solutions Architect @Pivotal Japan Spring Framework 💖 Cloud Foundry 💖
  3. 3. Platform Spring Specific Comparison 3 AWS BeanStalk Azure WebApps Google AppEngine Heroku OpenShift /k8s PCF/ PWS Spring Cloud Connector Spring Cloud Connector Heroku Spring Cloud Connector Cloud Foundry Spring Boot Integration * cloud profile * Apps Manager Spring Boot Actuator Support * Metric Forwarder Spring Cloud Integration Spring Cloud AWS Spring Cloud GCP * Spring Cloud Kubernetes * SCDF * Spring Cloud Services * Trace Exporter * SCDF
  4. 4. Platform Spring Specific Comparison 3 AWS BeanStalk Azure WebApps Google AppEngine Heroku OpenShift /k8s PCF/ PWS Spring Cloud Connector Spring Cloud Connector Heroku Spring Cloud Connector Cloud Foundry Spring Boot Integration * cloud profile * Apps Manager Spring Boot Actuator Support * Metric Forwarder Spring Cloud Integration Spring Cloud AWS Spring Cloud GCP * Spring Cloud Kubernetes * SCDF * Spring Cloud Services * Trace Exporter * SCDF
  5. 5. Why PCF for Spring? 4
  6. 6. Why PCF for Spring? 4 Because Pivotal Cloud Foundry gives us a lot of out-of-the-box features to manage / operate Spring Boot apps
  7. 7. Why PCF for Spring? 4 Because Pivotal Cloud Foundry gives us a lot of out-of-the-box features to manage / operate Spring Boot apps
  8. 8. Why PCF for Spring? 4 Because Pivotal Cloud Foundry gives us a lot of out-of-the-box features to manage / operate Spring Boot apps 12 Factors Apps Microservices Security Tracing Metrics
  9. 9. Spring Support in PCF 5 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  10. 10. Spring Support in PCF 6 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  11. 11. "profile" in Spring 7 without PCF/PWS myapp.foo=I am in local env. message=I am a default property. logging.level.com.example=DEBUG myapp.foo=I am in AWS. message=I am a production property logging.level.com.example=INFO application.properties application-prod.properties java -jar app.jar --spring.profiles.active=prod
  12. 12. cloud profile 8 with PCF/PWS myapp.foo=I am in local env. message=I am a default property. logging.level.com.example=DEBUG myapp.foo=I am in cloud foundry. message=I am a cloud property. logging.level.com.example=INFO application.properties application-cloud.properties java -jar app.jar --spring.profiles.active=cloud
  13. 13. cloud profile 8 with PCF/PWS myapp.foo=I am in local env. message=I am a default property. logging.level.com.example=DEBUG myapp.foo=I am in cloud foundry. message=I am a cloud property. logging.level.com.example=INFO application.properties application-cloud.properties java -jar app.jar --spring.profiles.active=cloud cloud profile is set by java-buildpack
  14. 14. Spring Support in PCF 9 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  15. 15. Attach backend services 10 without PCF/PWS spring.datasource.url=real-db.example.com spring.datasource.username=real-db-user spring.datasource.password=readl-db-password spring.rabbitmq.addresses=real-rabbit.example.com spring.rabbitmq.username=real-rabbit-user spring.rabbitmq.password=real-rabbit-password spring.rabbitmq.virtual-host=real-vhost application-prod.properties
  16. 16. Attach backend services 11 without PCF/PWS spring.datasource.url=${DB_URL} spring.datasource.username=${DB_USERNAME} spring.datasource.password=${DB_PASSWORD} spring.rabbitmq.addresses=${RABBIT_URL} spring.rabbitmq.username=${RABBIT_USERNAME} spring.rabbitmq.password=${RABBIT_PASSWORD} spring.rabbitmq.virtual-host=${RABBIT_VHOST} application-prod.properties
  17. 17. Attach backend services 11 without PCF/PWS spring.datasource.url=${DB_URL} spring.datasource.username=${DB_USERNAME} spring.datasource.password=${DB_PASSWORD} spring.rabbitmq.addresses=${RABBIT_URL} spring.rabbitmq.username=${RABBIT_USERNAME} spring.rabbitmq.password=${RABBIT_PASSWORD} spring.rabbitmq.virtual-host=${RABBIT_VHOST} application-prod.properties export DB_URL=real-db.example.com export DB_USERNAME=real-db-user export DB_PASSWORD=real-db-password ...
  18. 18. Spring Cloud Connectors 12 with PCF/PWS @Profile("cloud") public class CloudConfig extends AbstractCloudConfig { @Bean public DataSource dataSource() { return connectionFactory().dataSource(); } @Bean public ConnectionFactory rabbitConnectionFactory() { return connectionFactory().rabbitConnectionFactory(); } }
  19. 19. Spring Cloud Connectors 12 with PCF/PWS @Profile("cloud") public class CloudConfig extends AbstractCloudConfig { @Bean public DataSource dataSource() { return connectionFactory().dataSource(); } @Bean public ConnectionFactory rabbitConnectionFactory() { return connectionFactory().rabbitConnectionFactory(); } } cf bind-service myapp mydb cf bind-service myapp myrabbit
  20. 20. Spring Cloud Connectors 13 with PCF/PWS <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-spring-service-connector</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-cloudfoundry-connector</artifactId> </dependency>
  21. 21. Spring Cloud Connectors 14 • RDB • RabbitMQ • Redis • MongoDB • SMTP • Spring Cloud Services (Config Server, Eureka, Hystrix Dashboard) [1] • Vault [2] • .... with PCF/PWS [1] ... https://github.com/pivotal-cf/spring-cloud-services-connector [2] ... https://github.com/pivotal-cf/spring-cloud-vault-connector
  22. 22. ⚠ Do NOT use default datasource 15 with PCF/PWS https://discuss.pivotal.io/hc/en-us/articles/221898227-Connection-pool-warning-message-maxIdle-is-larger-than- maxActive-setting-maxIdle-to-4-seen-in-PCF-deployed-Spring-app org.apache.tomcat.jdbc.pool.ConnectionPool WARNING maxIdle is larger than maxActive, setting maxIdle to: 4
  23. 23. ⚠ Do NOT use default datasource 15 with PCF/PWS https://discuss.pivotal.io/hc/en-us/articles/221898227-Connection-pool-warning-message-maxIdle-is-larger-than- maxActive-setting-maxIdle-to-4-seen-in-PCF-deployed-Spring-app org.apache.tomcat.jdbc.pool.ConnectionPool WARNING maxIdle is larger than maxActive, setting maxIdle to: 4 org.apache.tomcat.jdbc.pool.PoolExhaustedException: [...] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:4; busy:4; idle:0; lastwait:30000] 😱
  24. 24. ⚠ Do NOT use default datasource 16 with PCF/PWS @Profile("cloud") public class CloudConfig extends AbstractCloudConfig { @Bean public DataSource dataSource() { PooledServiceConnectorConfig.PoolConfig poolConfig = new PooledServiceConnectorConfig.PoolConfig( 5 /* min */, 30 /* max */, 3000 /* wait */); return connectionFactory() .dataSource(new DataSourceConfig(poolConfig, null)); } }
  25. 25. Spring Support in PCF 17 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  26. 26. Microservices with Spring Cloud 18 without PCF/PWS Spring Boot App Spring Boot App Service Registry (Eureka) Config Server Circuit Breaker Dashboard (Hystrix Dashboard) You manage (deploy + security) You manage (deploy + security) You manage (deploy + security)
  27. 27. Spring Cloud Services 19 with PCF/PWS Spring Boot App Spring Boot App Service Registry (Eureka) Config Server Circuit Breaker Dashboard (Hystrix Dashboard) PCF manage (cf cs & cf bs) PCF manage (cf cs & cf bs) PCF manage (cf cs & cf bs) 19 UAA
  28. 28. Spring Support in PCF 20 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  29. 29. Distributed Tracing with Zipkin 21 Spring Boot App Spring Boot App Spring Boot App without PCF/PWS Spring Boot App Zipkin You manage (deploy + security) X-B3-SpaceId X-B3-TraceId
  30. 30. Distributed Tracing with Zipkin 22 spring.zipkin.url=my-zipkin.example.com without PCF/PWS
  31. 31. Trace Exporter 23 Spring Boot App Spring Boot App PCF Metrics with PCF/PWS Trace Exporter GoRouter Spring Boot App Spring Boot App X-B3-SpaceId X-B3-TraceId
  32. 32. Trace Exporter 24
  33. 33. Trace Exporter 25
  34. 34. Spring Support in PCF 26 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  35. 35. Spring Boot Actuator 27 Spring Boot Actuator /health, /info, /loggers, /dump
  36. 36. Spring Boot Actuator 27 Spring Boot Actuator /health, /info, /loggers, /dump Secured by default since Spring Boot 1.5. ROLE_ACTUATOR is required.
  37. 37. Secured by Default (since Spring Boot 1.5) 28 🔒
  38. 38. 29 😛 management.security.enabled=false
  39. 39. 29 😛 management.security.enabled=false 🙅
  40. 40. 30 management.security.enabled=true management.security.enabled=false application.properties application-cloud.properties
  41. 41. Many users say ... 31
  42. 42. Many users say ... 31 "Actuator is actually useful, but it is not for production, right?"
  43. 43. Nooooooooooooooooo!!!!! 32
  44. 44. Nooooooooooooooooo!!!!! 32 http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready.html
  45. 45. Secure with Spring Security 33 without PCF/PWS @EnableWebSecurity @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.antMatcher("/admin/**").authorizedRequests() .anyRequest().hasRole("ACTUATOR") .and().httpBasic() .and().csrf().disable(); } // ... } management.context-path=/admin
  46. 46. Spring Actuator Support in Apps Manager 34 Spring Boot Actuator /cloudfoundryapplication/health, /cloudfoundryapplication/info, ... Apps Manager UAA token token with PCF/PWS Cloud Controller token permission
  47. 47. Spring Actuator Support in Apps Manager 5 Endpoint Description Supported Version /dump Get thread dump 🆕 1.11~ /env Get env variables, properties /metrics Get application's metrics /health Get the result of health checks ✅ 1.9~ /info Get build information ✅ 1.9~ /loggers Change logging level ✅ 1.9~ /trace Get request trace log 🆕 1.11~ /heapdump Download heap dump 🆕 1.11~
  48. 48. Apps Manager 36
  49. 49. /health 37
  50. 50. /info 38
  51. 51. /loggers 39
  52. 52. /dump 40
  53. 53. /dump 41
  54. 54. /trace 42
  55. 55. /heapdump 43
  56. 56. /heapdump 44
  57. 57. /heapdump 45
  58. 58. /heapdump 46
  59. 59. Spring Support in PCF 47 • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  60. 60. Spring Actuator Support in Apps Manager 8 Endpoint Description Supported Version /dump Get thread dump 🆕 1.11~ /env Get env variables, properties /metrics Get application's metrics /health Get the result of health checks ✅ 1.9~ /info Get build information ✅ 1.9~ /loggers Change logging level ✅ 1.9~ /trace Get request trace log 🆕 1.11~ /heapdump Download heap dump 🆕 1.11~
  61. 61. Spring Actuator Support in Apps Manager 8 Endpoint Description Supported Version /dump Get thread dump 🆕 1.11~ /env Get env variables, properties /metrics Get application's metrics /health Get the result of health checks ✅ 1.9~ /info Get build information ✅ 1.9~ /loggers Change logging level ✅ 1.9~ /trace Get request trace log 🆕 1.11~ /heapdump Download heap dump 🆕 1.11~
  62. 62. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics
  63. 63. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics Metrics Writer
  64. 64. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics Metrics Writer TSDB or ...
  65. 65. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics Redis, OpenTSDB, Statsd, JMX Metrics Writer TSDB or ...
  66. 66. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics send Redis, OpenTSDB, Statsd, JMX Metrics Writer TSDB or ...
  67. 67. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics send Redis, OpenTSDB, Statsd, JMX Dashboard Metrics Writer TSDB or ...
  68. 68. Spring Boot Actuator Metrics 49 Spring Boot Actuator /metrics send Redis, OpenTSDB, Statsd, JMX Dashboard You configure Metrics Writer TSDB or ...
  69. 69. Metrics Writer 50 @Bean @ExportMetricWriter MetricWriter metricWriter(MetricExportProperties export){ return new RedisMetricRepository(connectionFactory, export.getRedis().getPrefix(), export.getRedis().getKey()); } docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html#production-ready-metric-writers without PCF/PWS
  70. 70. Metrics Forwarder Service 51 comes with java buildpack v3.18/4.2+ Enables Actuator's MetricsWriter to Metrics Forwarder Service automatically https://github.com/cloudfoundry/java-buildpack-metric-writer https://github.com/cloudfoundry/java-buildpack/blob/master/docs/framework-metric_writer.md with PCF/PWS
  71. 71. Metrics Forwarder Service 52 Spring Boot Actuator Metrics Writer Java buildpack Metrics Forwarder Service bind TSDB Dashboard send send with PCF/PWS
  72. 72. Metrics Forwarder Service 53 cf bind-service myapp mf cf cups mf -p '{"endpoint":"X","access_token":"X"}' cf create-service metric-forwarder plan mf OR THEN with PCF/PWS
  73. 73. DEMO Scenario 54 Spring Boot Actuator Metrics Writer Java buildpack Metrics Forwarder Service bind Grafana Prometheus scrape send works as * Metrics Forwarder Service * Service Broker * Prometheus Exporter PromQL
  74. 74. 55
  75. 75. Source code 56 https://github.com/making/prometheus-exporter- metrics-forwarder-service
  76. 76. Integration with PCF (Future) 57 Spring Boot Actuator Metrics Writer Java buildpack Metrics Forwarder Service bind PCF Metrics, Autoscaler send send will be provided as a "tile"
  77. 77. Recap 58 Why PCF is best platform for Spring ➡ a lot of out-of-the-box features • cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service
  78. 78. https://www.youtube.com/watch?v=9rPjLaOkEUo 59

×