Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Spring on Google Cloud Platform

Spring on Google Cloud Platform

Pivotal and Google Cloud Platform (GCP) collaborate on a number of projects—including Pivotal Cloud Foundry Service Broker for GCP and Spring Boot starters—that make it easy to leverage GCP's managed services, whether you are starting a new project or migrating an existing on-premise project.

In this talk, we'll examine different GCP-created tools that help you develop and run Java and Spring applications, such as Spring Cloud GCP. In addition, we'll look at the different runtime environments that you can deploy to, such as Google Kubernetes Engine, App Engine, and Pivotal Cloud Foundry with GCP Service Broker.

Finally, we'll go over some of the platform services that help you monitor, troubleshoot, profile, and debug your Java production application.

Webinar: https://content.pivotal.io/webinars/jul-12-spring-on-google-cloud-platform-webinar

Ray Tsang

July 12, 2018
Tweet

More Decks by Ray Tsang

Other Decks in Technology

Transcript

  1. Spring on Google Cloud Platform

    View Slide

  2. 2
    @saturnism @gcpcloud
    Ray Tsang
    Developer Advocate
    Google Cloud Platform
    @saturnism saturnism.me

    View Slide

  3. 3
    @saturnism @gcpcloud
    Compute Big Data
    BigQuery
    Cloud
    Dataflow
    Cloud
    Dataproc
    Cloud
    Datalab
    Cloud
    Pub/Sub
    Genomics
    Storage & Databases
    Cloud
    Storage
    Cloud
    Bigtable
    Cloud
    Datastore
    Cloud SQL
    Cloud
    Spanner
    Persistent
    Disk
    Machine Learning
    Cloud Machine
    Learning
    Cloud
    Vision API
    Cloud
    Speech API
    Cloud Natural
    Language API
    Cloud
    Translation
    API
    Cloud
    Jobs API
    Data
    Studio
    Cloud
    Dataprep
    Cloud Video
    Intelligence
    API
    Advanced
    Solutions Lab
    Compute
    Engine
    App
    Engine
    Kubernetes
    Engine
    GPU
    Cloud
    Functions
    Container-
    Optimized OS
    Identity & Security
    Cloud IAM
    Cloud Resource
    Manager
    Cloud Security
    Scanner
    Key
    Management
    Service
    BeyondCorp
    Data Loss
    Prevention API
    Identity-Aware
    Proxy
    Security Key
    Enforcement
    Data
    Transfer
    Appliance

    View Slide

  4. 4
    @saturnism @gcpcloud
    Amazing Technology!

    View Slide

  5. 5
    @saturnism @gcpcloud
    Use Spring on Google Cloud Platform
    as easily and seamlessly as possible

    View Slide

  6. 6
    @saturnism @gcpcloud
    Framework
    IDE and Tooling
    Deployment
    Monitoring/Diagnostics

    View Slide

  7. 7
    @saturnism @gcpcloud
    Goals
    Provide integration between GCP
    services and Spring
    Meet developers where they are
    Cut down on boilerplate code
    +

    View Slide

  8. 8
    @saturnism @gcpcloud
    Collaboration with
    Pivotal
    Developed GitHub in the spring-cloud-gcp
    repository under the Spring Cloud organization
    owned by Pivotal.
    Close collaboration between Google and
    Pivotal engineers.

    View Slide

  9. 9
    @saturnism @gcpcloud
    Feature GCP Service Spring Framework
    Configuration Cloud Runtime Config Spring Cloud Config
    Messaging Cloud Pub/Sub Spring Integration
    Spring Cloud Stream
    Spring Dataflow
    Database Cloud SQL
    Cloud Spanner
    Spring Data
    Spring Data Spanner
    Storage Cloud Storage Spring Resource
    Logging Stackdriver Logging Logback
    Trace Stackdriver Trace Spring Cloud Sleuth
    Spring Boot Starters for...

    View Slide

  10. 10
    @saturnism @gcpcloud

    View Slide

  11. 11
    @saturnism @gcpcloud



    org.springframework.cloud
    spring-cloud-gcp-dependencies
    ${spring-cloud-gcp.version}
    pom
    import



    View Slide

  12. 12
    @saturnism @gcpcloud
    Cloud SQL database
    Spring Boot App

    View Slide

  13. 13
    @saturnism @gcpcloud
    Cloud SQL
    Managed MySQL and PostgreSQL
    Scale out with read replicas
    High availability (HA) option
    Per-minute billing
    Instance sizes to fit any budget
    Granular access control using IAM roles

    View Slide

  14. 14
    @saturnism @gcpcloud
    pom.xml

    org.springframework.cloud
    spring-cloud-gcp-starter-sql-mysql

    application.properties
    spring.cloud.gcp.sql.instance-connection-name=my-gcp-project:us-central1:petclinic
    spring.cloud.gcp.sql.database-name=petclinic_db
    Configures Datasource, JDBC URL, Certificates
    Establishes secured connections

    View Slide

  15. 15
    @saturnism @gcpcloud
    Message
    Processor
    Processor 2
    Processor N
    ...
    Google Cloud Pub/Sub
    Google Cloud SQL database
    Spring Boot app

    View Slide

  16. 16
    @saturnism @gcpcloud
    Managed Global Messaging Middleware
    Capture, pass messages across services
    At-least- once delivery semantics
    Configurable message retention policies
    Push/Pull message delivery patterns
    Cloud
    Pub/Sub

    View Slide

  17. 17
    @saturnism @gcpcloud

    View Slide

  18. 18
    @saturnism @gcpcloud
    pom.xml

    org.springframework.cloud
    spring-cloud-gcp-starter-pubsub

    Code
    @Autowired PubSubTemplate pubSubTemplate;
    public void hello(String name) {
    pubSubTemplate.publish("my-topic", name + " said Hi");
    }

    View Slide

  19. 19
    @saturnism @gcpcloud

    View Slide

  20. 20
    @saturnism @gcpcloud
    Code
    pubSubTemplate.subscribe("processors", (msg, ackReply) -> {
    log.info(msg.getData().toStringUtf8());
    ackReply.ack();
    });

    View Slide

  21. 21
    @saturnism @gcpcloud
    Also Integrated Pub/Sub with...
    Spring Framework Use Case
    Spring Integration Enterprise Integration Pattern
    Middleware-Agnostic Code
    Spring Cloud Stream Event-driven Microservices
    Reactive Programming
    Middleware-Agnostic Code

    View Slide

  22. 22
    @saturnism @gcpcloud
    Scalable mission-critical RDBMS
    Relational semantics
    Schemas, ACID transactions, SQL query
    Scale horizontally
    Automatic, synchronous replication
    99.999% Availability
    Cloud
    Spanner

    View Slide

  23. 23
    @saturnism @gcpcloud
    pom.xml

    org.springframework.cloud
    spring-cloud-gcp-starter-data-spanner<

    Code
    @Table
    public class Person {
    @PrimaryKey
    private long id;
    private String id;
    ...
    }

    View Slide

  24. 24
    @saturnism @gcpcloud
    Code
    @RepositoryRestResource
    public interface PersonRestRepository extends SpannerRepository {
    public List findPersonByName(String name);
    @Query("SELECT * FROM person WHERE ...")
    public List findPersonWithQuery(String location);
    }

    View Slide

  25. 25
    @saturnism @gcpcloud
    Observability, Correlated Logs with
    Sleuth and Logback

    View Slide

  26. 26
    @saturnism @gcpcloud
    pom.xml

    org.springframework.cloud
    spring-cloud-gcp-starter-logging


    org.springframework.cloud
    spring-cloud-gcp-starter-trace

    View Slide

  27. 27
    @saturnism @gcpcloud
    Log Appender
    Direct to Stackdriver Logging
    Or, Output as XML

    View Slide

  28. 28
    @saturnism @gcpcloud

    View Slide

  29. 29
    @saturnism @gcpcloud

    View Slide

  30. 30
    @saturnism @gcpcloud

    View Slide

  31. 31
    @saturnism @gcpcloud
    Feature GCP Service Spring Framework
    Configuration Cloud Runtime Config Spring Cloud Config
    Messaging Cloud Pub/Sub Spring Integration
    Spring Cloud Stream
    Spring Dataflow
    Database Cloud SQL
    Cloud Spanner
    Spring Data
    Spring Data Spanner
    Storage Cloud Storage Spring Resource
    Logging Stackdriver Logging Logback
    Trace Stackdriver Trace Spring Cloud Sleuth
    Spring Boot Starters for...

    View Slide

  32. 32
    @saturnism @gcpcloud
    IntelliJ and Eclipse Plugins
    Maven and Gradle Plugins

    View Slide

  33. 33
    @saturnism @gcpcloud

    View Slide

  34. 34
    @saturnism @gcpcloud

    View Slide

  35. 35
    @saturnism @gcpcloud
    Automatically adds dependencies to POM

    View Slide

  36. 36
    @saturnism @gcpcloud
    pom.xml

    com.google.cloud
    google-cloud-vision

    Code
    @Bean
    public ImageAnnotatorClient imageAnnotatorClient(
    CredentialsProvider credentialsProvider) throws IOException {
    ImageAnnotatorSettings clientSettings = ImageAnnotatorSettings.newBuilder()
    .setCredentialsProvider(credentialsProvider)
    .build();
    return ImageAnnotatorClient.create(clientSettings);
    }

    View Slide

  37. 37
    @saturnism @gcpcloud
    App Engine
    Standard
    Kubernetes
    Engine
    Compute
    Engine

    View Slide

  38. 38
    @saturnism @gcpcloud

    View Slide

  39. 39
    @saturnism @gcpcloud
    pom.xml

    com.google.cloud.tools
    appengine-maven-plugin
    1.3.1

    Deploy
    $ mvn appengine:deploy

    View Slide

  40. 40
    @saturnism @gcpcloud
    Jib - building container images
    https://github.com/GoogleContainerTools/jib
    Fast - Automatically split application into layers based on application dependency.
    Reproducible - Rebuilding your container image with the same contents always generates the same
    image.
    Daemonless - Reduce CLI dependencies. Build container image from within Maven or Gradle and
    push to any registry of your choice. No more writing Dockerfiles and calling docker build/push.
    Small - Uses Google's Distroless base image,

    View Slide

  41. 41
    @saturnism @gcpcloud
    pom.xml

    com.google.cloud.tools
    jib-maven-plugin
    ...


    my-spring-app



    Deploy
    $ mvn compile jib:build

    View Slide

  42. 42
    @saturnism @gcpcloud
    Pivotal Cloud Foundry Support

    View Slide

  43. 43
    @saturnism @gcpcloud
    Pivotal Cloud Foundry Support
    Native - Google and Pivotal engineers built support for PCF on GCP. Use things like global load
    balancing and pre-emptible VMs to scale applications or reduce cost.
    Integrated - The GCP Service Broker lets developers provision and use Google services in their apps
    without manually creating and managing resources in the console.
    Observable - Stackdriver debugging, monitoring, and logging make it easy to observe your Spring
    applications deployed to PCF on GCP.

    View Slide

  44. 44
    @saturnism @gcpcloud
    GCP Service Broker for Cloud Foundry
    VIRTUAL NETWORK
    LOAD BALANCING
    CDN
    DNS
    INTERCONNECT
    Management Compute Storage Networking Data
    Machine
    Learning
    STACKDRIVER
    IDENTITY AND
    ACCESS
    MANAGEMENT
    CLOUD ML
    SPEECH API
    VISION API
    TRANSLATE API
    44
    NATURAL
    LANGUAGE API

    View Slide

  45. 45
    @saturnism @gcpcloud
    cf create-service SERVICE PLAN SERVICE_INSTANCE [-c PARAMETERS_AS_JSON] [-t TAGS]
    # generated topic name, no subscription
    $ cf create-service pubsub default orders
    # generated topic name, with a subscription
    $ cf create-service pubsub default orders -c \
    '{"topic-name": "orders", "subscription-name": "accounting"}'
    cf bind-service APP_NAME SERVICE_INSTANCE [-c PARAMETERS_AS_JSON] [--binding-name
    BINDING_NAME]
    $ cf bind-service accounting-database orders -c '{"role": "pubsub.subscriber"}'
    $ cf bind-service website orders -c '{"role": "pubsub.publisher"}'

    View Slide

  46. 46
    @saturnism @gcpcloud
    Spring Cloud GCP
    Automatically Discovers
    VCAP_SERVICES Environment Variable
    Configures Credentials

    View Slide

  47. 47
    @saturnism @gcpcloud
    Prometheus Monitoring with Stackdriver

    View Slide

  48. 48
    @saturnism @gcpcloud
    pom.xml

    org.springframework.boot
    spring-boot-starter-actuator


    io.micrometer
    micrometer-registry-prometheus
    runtime

    Prometheus Endpoint
    $ curl http://localhost:8080/actuator/prometheus

    View Slide

  49. 49
    @saturnism @gcpcloud
    jvm_gc_max_data_size_bytes 8.9653248E7
    tomcat_global_request_seconds_count{name="http-nio-8080",} 322145.0
    tomcat_global_request_seconds_sum{name="http-nio-8080",} 748.139
    process_uptime_seconds 26874.681
    tomcat_global_error_total{name="http-nio-8080",} 1.0
    jvm_buffer_memory_used_bytes{id="direct",} 294913.0
    jvm_buffer_memory_used_bytes{id="mapped",} 0.0
    tomcat_servlet_request_max_seconds{name="default",} 0.0
    system_cpu_usage 0.06456190138346932
    process_files_max 1048576.0
    http_server_requests_seconds_count{exception="None",method="GET",status="200",uri="/**",} 322111.0
    http_server_requests_seconds_sum{exception="None",method="GET",status="200",uri="/**",} 527.459778932
    http_server_requests_seconds_count{exception="None",method="GET",status="404",uri="/webjars/**",} 1.0
    http_server_requests_seconds_sum{exception="None",method="GET",status="404",uri="/webjars/**",} 0.026788256
    http_server_requests_seconds_count{exception="None",method="GET",status="304",uri="/**",} 33.0
    http_server_requests_seconds_sum{exception="None",method="GET",status="304",uri="/**",} 0.171848745
    http_server_requests_seconds_count{exception="None",method="GET",status="200",uri="/api/gateway/owners/{ownerId}",} 3.0
    http_server_requests_seconds_sum{exception="None",method="GET",status="200",uri="/api/gateway/owners/{ownerId}",} 1.247613785
    http_server_requests_seconds_max{exception="None",method="GET",status="200",uri="/**",} 0.073825406
    http_server_requests_seconds_max{exception="None",method="GET",status="404",uri="/webjars/**",} 0.0
    http_server_requests_seconds_max{exception="None",method="GET",status="304",uri="/**",} 0.0
    http_server_requests_seconds_max{exception="None",method="GET",status="200",uri="/api/gateway/owners/{ownerId}",} 0.0
    system_cpu_count 2.0
    tomcat_threads_busy{name="http-nio-8080",} 0.0
    tomcat_sessions_active_max 0.0
    jvm_threads_live 69.0
    tomcat_servlet_request_seconds_count{name="default",} 0.0
    tomcat_servlet_request_seconds_sum{name="default",} 0.0
    jvm_memory_committed_bytes{area="nonheap",id="Code Cache",} 4.2205184E7
    jvm_memory_committed_bytes{area="nonheap",id="Metaspace",} 7.3269248E7
    jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space",} 8781824.0
    jvm_memory_committed_bytes{area="heap",id="PS Eden Space",} 4.0370176E7
    jvm_memory_committed_bytes{area="heap",id="PS Survivor Space",} 2097152.0
    jvm_memory_committed_bytes{area="heap",id="PS Old Gen",} 6.029312E7
    jvm_memory_max_bytes{area="nonheap",id="Code Cache",} 2.5165824E8
    jvm_memory_max_bytes{area="nonheap",id="Metaspace",} -1.0
    jvm_memory_max_bytes{area="nonheap",id="Compressed Class Space",} 1.073741824E9
    jvm_memory_max_bytes{area="heap",id="PS Eden Space",} 4.0370176E7
    jvm_memory_max_bytes{area="heap",id="PS Survivor Space",} 2097152.0
    jvm_memory_max_bytes{area="heap",id="PS Old Gen",} 8.9653248E7
    ...

    View Slide

  50. 50
    @saturnism @gcpcloud

    View Slide

  51. 51
    @saturnism @gcpcloud

    View Slide

  52. 52
    @saturnism @gcpcloud
    Production Debugging and Profiling

    View Slide

  53. 53
    @saturnism @gcpcloud
    Download the Agents
    Add to Startup Command Line:
    For Profiler:
    $ java -agentpath:/opt/profiler/profiler_java_agent.so=... -jar myapp.jar
    For Debugger:
    $ java -agentpath:/opt/debugger/cdbg_java_agent.so -jar myapp.jar

    View Slide

  54. 54
    @saturnism @gcpcloud
    What's taking most CPU time?

    View Slide

  55. 55
    @saturnism @gcpcloud

    View Slide

  56. 56
    @saturnism @gcpcloud
    Forgot a Log Message?

    View Slide

  57. 57
    @saturnism @gcpcloud

    View Slide

  58. 58
    @saturnism @gcpcloud

    View Slide

  59. 59
    @saturnism @gcpcloud
    Debug Production Code, Live!

    View Slide

  60. 60
    @saturnism @gcpcloud

    View Slide

  61. 61
    @saturnism @gcpcloud

    View Slide

  62. 62
    @saturnism @gcpcloud

    View Slide

  63. 63
    @saturnism @gcpcloud

    View Slide

  64. 64
    @saturnism @gcpcloud
    PCF Buildpack with GCP Service Broker
    Automatically adds Debugger Agent on `cf push`!

    View Slide

  65. 65
    @saturnism @gcpcloud
    Framework - Spring Boot Support
    IDE and Tooling - IntelliJ, Eclipse, Maven, Gradle
    Deployment - Container, App Engine, PCF, ...
    Monitoring/Diagnostics - Debug, Profile, Logging, Error Reporting, Prometheus Monitoring, ...
    End-to-end Developer Experience

    View Slide

  66. 66
    @saturnism @gcpcloud
    Project Home https://cloud.spring.io/spring-cloud-gcp/
    Documentation https://docs.spring.io/spring-cloud-gcp/docs/
    Source and Samples https://github.com/spring-cloud/spring-cloud-gcp/
    Short Code Labs http://g.co/codelabs/spring
    Long Code Lab http://bit.ly/spring-gcp-lab
    Recorded Conference Talks
    ○ Power of Google Cloud Platform with Spring Cloud GCP
    ○ Cloud Native with Spring Boot on Google Cloud Platform

    View Slide

  67. Thanks!
    cloud.spring.io/spring-cloud-gcp
    http://bit.ly/spring-gcp-lab
    @saturnism

    View Slide