Top Banner
Why PCF is the best platform for Spring Boot 2017-07-20 Toshiaki Maki (@making)
78

Why PCF is the best platform for Spring Boot

Mar 17, 2018

Download

Technology

Toshiaki Maki
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Why PCF is the best platform for Spring Boot

1

Why PCF is the best platform for Spring Boot

2017-07-20 Toshiaki Maki (@making)

Page 2: Why PCF is the best platform for Spring Boot

Who am I ?

2

Toshiaki Maki (@making) https://blog.ik.am Sr. Solutions Architect @Pivotal Japan Spring Framework 💖 Cloud Foundry 💖

Page 3: Why PCF is the best platform for Spring Boot

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

Page 4: Why PCF is the best platform for Spring Boot

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

Page 5: Why PCF is the best platform for Spring Boot

Why PCF for Spring?

4

Page 6: Why PCF is the best platform for Spring Boot

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

Page 7: Why PCF is the best platform for Spring Boot

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

Page 8: Why PCF is the best platform for Spring Boot

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

Page 9: Why PCF is the best platform for Spring Boot

Spring Support in PCF

5

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 10: Why PCF is the best platform for Spring Boot

Spring Support in PCF

6

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 11: Why PCF is the best platform for Spring Boot

"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 propertylogging.level.com.example=INFO

application.properties

application-prod.properties

java -jar app.jar --spring.profiles.active=prod

Page 12: Why PCF is the best platform for Spring Boot

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

Page 13: Why PCF is the best platform for Spring Boot

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

Page 14: Why PCF is the best platform for Spring Boot

Spring Support in PCF

9

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 15: Why PCF is the best platform for Spring Boot

Attach backend services

10

without PCF/PWS

spring.datasource.url=real-db.example.comspring.datasource.username=real-db-userspring.datasource.password=readl-db-password

spring.rabbitmq.addresses=real-rabbit.example.comspring.rabbitmq.username=real-rabbit-userspring.rabbitmq.password=real-rabbit-passwordspring.rabbitmq.virtual-host=real-vhost

application-prod.properties

Page 16: Why PCF is the best platform for Spring Boot

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

Page 17: Why PCF is the best platform for Spring Boot

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.comexport DB_USERNAME=real-db-userexport DB_PASSWORD=real-db-password...

Page 18: Why PCF is the best platform for Spring Boot

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(); }}

Page 19: Why PCF is the best platform for Spring Boot

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 mydbcf bind-service myapp myrabbit

Page 20: Why PCF is the best platform for Spring Boot

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>

Page 21: Why PCF is the best platform for Spring Boot

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

Page 22: Why PCF is the best platform for Spring Boot

⚠ 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

Page 23: Why PCF is the best platform for Spring Boot

⚠ 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: 4org.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]

😱

Page 24: Why PCF is the best platform for Spring Boot

⚠ 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)); }}

Page 25: Why PCF is the best platform for Spring Boot

Spring Support in PCF

17

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 26: Why PCF is the best platform for Spring Boot

Microservices with Spring Cloud

18

without PCF/PWS

Spring Boot App

Spring Boot App

Service Registry (Eureka) Config ServerCircuit Breaker Dashboard

(Hystrix Dashboard)

You manage (deploy + security)

You manage (deploy + security)

You manage (deploy + security)

Page 27: Why PCF is the best platform for Spring Boot

Spring Cloud Services

19

with PCF/PWS

Spring Boot App

Spring Boot App

Service Registry (Eureka) Config ServerCircuit Breaker Dashboard

(Hystrix Dashboard)

PCF manage (cf cs & cf bs)

PCF manage (cf cs & cf bs)

PCF manage (cf cs & cf bs)

19

UAA

Page 28: Why PCF is the best platform for Spring Boot

Spring Support in PCF

20

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 29: Why PCF is the best platform for Spring Boot

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

Page 30: Why PCF is the best platform for Spring Boot

Distributed Tracing with Zipkin

22

spring.zipkin.url=my-zipkin.example.com

without PCF/PWS

Page 31: Why PCF is the best platform for Spring Boot

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

Page 32: Why PCF is the best platform for Spring Boot

Trace Exporter

24

Page 33: Why PCF is the best platform for Spring Boot

Trace Exporter

25

Page 34: Why PCF is the best platform for Spring Boot

Spring Support in PCF

26

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 35: Why PCF is the best platform for Spring Boot

Spring Boot Actuator

27

Spring Boot Actuator

/health, /info, /loggers, /dump

Page 36: Why PCF is the best platform for Spring Boot

Spring Boot Actuator

27

Spring Boot Actuator

/health, /info, /loggers, /dump

Secured by default since Spring Boot 1.5.

ROLE_ACTUATOR is required.

Page 37: Why PCF is the best platform for Spring Boot

Secured by Default (since Spring Boot 1.5)

28

🔒

Page 38: Why PCF is the best platform for Spring Boot

29

😛management.security.enabled=false

Page 39: Why PCF is the best platform for Spring Boot

29

😛management.security.enabled=false

🙅

Page 40: Why PCF is the best platform for Spring Boot

30

management.security.enabled=true

management.security.enabled=falseapplication.properties

application-cloud.properties

Page 41: Why PCF is the best platform for Spring Boot

Many users say ...

31

Page 42: Why PCF is the best platform for Spring Boot

Many users say ...

31

"Actuator is actually useful, but

it is not for production, right?"

Page 43: Why PCF is the best platform for Spring Boot

Nooooooooooooooooo!!!!!

32

Page 44: Why PCF is the best platform for Spring Boot

Nooooooooooooooooo!!!!!

32 http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready.html

Page 45: Why PCF is the best platform for Spring Boot

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

Page 46: Why PCF is the best platform for Spring Boot

Spring Actuator Support in Apps Manager

34

Spring Boot Actuator

/cloudfoundryapplication/health, /cloudfoundryapplication/info, ...

Apps Manager

UAA

token

token

with PCF/PWS

Cloud Controller

tokenpermission

Page 47: Why PCF is the best platform for Spring Boot

Spring Actuator Support in Apps Manager

35

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~

Page 48: Why PCF is the best platform for Spring Boot

Apps Manager

36

Page 49: Why PCF is the best platform for Spring Boot

/health

37

Page 50: Why PCF is the best platform for Spring Boot

/info

38

Page 51: Why PCF is the best platform for Spring Boot

/loggers

39

Page 52: Why PCF is the best platform for Spring Boot

/dump

40

Page 53: Why PCF is the best platform for Spring Boot

/dump

41

Page 54: Why PCF is the best platform for Spring Boot

/trace

42

Page 55: Why PCF is the best platform for Spring Boot

/heapdump

43

Page 56: Why PCF is the best platform for Spring Boot

/heapdump

44

Page 57: Why PCF is the best platform for Spring Boot

/heapdump

45

Page 58: Why PCF is the best platform for Spring Boot

/heapdump

46

Page 59: Why PCF is the best platform for Spring Boot

Spring Support in PCF

47

• cloud profile • Spring Cloud Connectors • Spring Cloud Services • Trace Exporter • Spring Actuator Support in Apps Manager • Metrics Forwarder Service

Page 60: Why PCF is the best platform for Spring Boot

Spring Actuator Support in Apps Manager

48

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~

Page 61: Why PCF is the best platform for Spring Boot

Spring Actuator Support in Apps Manager

48

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~

Page 62: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

Page 63: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

Metrics Writer

Page 64: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

Metrics Writer TSDB or ...

Page 65: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

Redis, OpenTSDB, Statsd, JMX

Metrics Writer TSDB or ...

Page 66: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

send

Redis, OpenTSDB, Statsd, JMX

Metrics Writer TSDB or ...

Page 67: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

send

Redis, OpenTSDB, Statsd, JMX

Dashboard

Metrics Writer TSDB or ...

Page 68: Why PCF is the best platform for Spring Boot

Spring Boot Actuator Metrics

49

Spring Boot Actuator

/metrics

send

Redis, OpenTSDB, Statsd, JMX

DashboardYou configure

Metrics Writer TSDB or ...

Page 69: Why PCF is the best platform for Spring Boot

Metrics Writer

50

@Bean@ExportMetricWriterMetricWriter 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

Page 70: Why PCF is the best platform for Spring Boot

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

Page 71: Why PCF is the best platform for Spring Boot

Metrics Forwarder Service

52

Spring Boot Actuator

Metrics WriterJava

build

pac

k Metrics Forwarder

Service

bind TSDB

Dashboard

send

send

with PCF/PWS

Page 72: Why PCF is the best platform for Spring Boot

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

Page 73: Why PCF is the best platform for Spring Boot

DEMO Scenario

54

Spring Boot Actuator

Metrics WriterJava

build

pac

k Metrics Forwarder

Service

bind

Grafana

Prometheusscrape

send

works as * Metrics Forwarder Service * Service Broker * Prometheus Exporter

PromQL

Page 74: Why PCF is the best platform for Spring Boot

55

Page 75: Why PCF is the best platform for Spring Boot

Source code

56

https://github.com/making/prometheus-exporter-metrics-forwarder-service

Page 76: Why PCF is the best platform for Spring Boot

Integration with PCF (Future)

57

Spring Boot Actuator

Metrics WriterJava

build

pac

k Metrics Forwarder

Service

bindPCF Metrics, Autoscalersend

send

will be provided as a "tile"

Page 77: Why PCF is the best platform for Spring Boot

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

Page 78: Why PCF is the best platform for Spring Boot

https://www.youtube.com/watch?v=9rPjLaOkEUo

59