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.

Spring Cloud’s Groovy

1,177 views

Published on

Spring Cloud’s Groovy presentation from Warsaw GR8 Day conference - http://warsaw.gr8days.pl

Published in: Technology
  • Be the first to comment

Spring Cloud’s Groovy

  1. 1. SpringCloud’sGroovy Marcin Grzejszczak, Pivotal @mgrzejszczak
  2. 2. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Aboutme Developer at Pivotal Part of Spring Cloud Team Working with OSS TWITTER: @MGrzejszczak BLOG: TOOMUCHCODING.COM
  3. 3. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Agenda What are we using Groovy for at Spring Cloud? Quick introduction to Distributed Tracing Why Gradle made it possible to test Spring Cloud? How we’re testing with Spock? DEMO
  4. 4. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Agenda What are we using Groovy for at Spring Cloud? Quick introduction to Distributed Tracing Why Gradle made it possible to test Spring Cloud? How we’re testing with Spock? DEMO
  5. 5. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhatareweusingGroovyforatSpringCloud? Spring Cloud Zookeeper tests with Spock End to end tests of Spring Cloud Zookeeper Consul Eureka Netflix (Zuul, Ribbon, Feign) Sleuth
  6. 6. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhatareweusingGroovyforatSpringCloud? Spring Cloud Zookeeper tests with Spock End to end tests of Spring Cloud Zookeeper Consul Eureka Netflix (Zuul, Ribbon, Feign) Sleuth
  7. 7. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Agenda What are we using Groovy for at Spring Cloud? Quick introduction to Distributed Tracing Why Gradle made it possible to test Spring Cloud? How we’re testing with Spock? DEMO
  8. 8. @MGrzejszczak @gr8day_warsaw #GR8DayWAW QuickIntroductionToDistributedTracing Modern applications are a gigantic net of interconected components It’s crucial to have tools that allow you visualize the system’s topology and performance issues Dapper, a Large-Scale Distributed Systems Tracing Infrastructure
  9. 9. @MGrzejszczak @gr8day_warsaw #GR8DayWAW QuickIntroductionToDistributedTracing Zipkin A distributed tracing system. Helps gather timing data needed to troubleshoot latency problems in microservice architectures The front end is a "waterfall" style graph of service calls showing call durations as horizontal bars
  10. 10. @MGrzejszczak @gr8day_warsaw #GR8DayWAW QuickIntroductionToDistributedTracing Spring Cloud Sleuth Implements a distributed tracing solution for Spring Cloud. Borrows Dapper’s terminology. Integrates with Zipkin
  11. 11. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology Span The basic unit of work (e.g. sending RPC) Spans are started and stopped They keep track of their timing information Once you create a span, you must stop it at some point in the future
  12. 12. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology Trace A set of spans forming a tree-like structure. For example, if you are running a book store then a trace could be retriving a list of available books
  13. 13. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology SERVICE 1 REQUEST No Trace Id No Span Id RESPONSE SERVICE 2 SERVICE 3 Trace Id = X Span Id = A Trace Id = X Span Id = A Trace Id = X Span Id = A REQUEST RESPONSE Trace Id = X Span Id = B Client Sent Trace Id = X Span Id = B Client Received Trace Id = X Span Id = B Server Received Trace Id = X Span Id = C Trace Id = X Span Id = B Server Sent REQUEST RESPONSE Trace Id = X Span Id = D Client Sent Trace Id = X Span Id = D Client Received Trace Id = X Span Id = D Server Received Trace Id = X Span Id = E Trace Id = X Span Id = D Server Sent Trace Id = X Span Id = E SERVICE 4 REQUEST RESPONSE Trace Id = X Span Id = F Client Sent Trace Id = X Span Id = F Client Received Trace Id = X Span Id = F Server Received Trace Id = X Span Id = G Trace Id = X Span Id = F Server Sent Trace Id = X Span Id = G Trace Id = X Span Id = C
  14. 14. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology Span Id = A Parent Id = null Span Id = B Parent Id = A Span Id = C Parent Id = B Span Id = D Parent Id = C Span Id = E Parent Id = D Span Id = F Parent Id = C Span Id = G Parent Id = F
  15. 15. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology SERVICE 1 /start REQUEST No Trace Id No Span Id RESPONSE SERVICE 2 /foo SERVICE 3 /bar Trace Id = X Span Id = A Trace Id = X Span Id = A Trace Id = X Span Id = A REQUEST RESPONSE Trace Id = X Span Id = B Client Sent Trace Id = X Span Id = B Client Received Trace Id = X Span Id = B Server Received Trace Id = X Span Id = C Trace Id = X Span Id = B Server Sent REQUEST RESPONSE Trace Id = X Span Id = D Client Sent Trace Id = X Span Id = D Client Received Trace Id = X Span Id = D Server Received Trace Id = X Span Id = E Trace Id = X Span Id = D Server Sent Trace Id = X Span Id = E SERVICE 4 /baz REQUEST RESPONSE Trace Id = X Span Id = F Client Sent Trace Id = X Span Id = F Client Received Trace Id = X Span Id = F Server Received Trace Id = X Span Id = G Trace Id = X Span Id = F Server Sent Trace Id = X Span Id = G Trace Id = X Span Id = C
  16. 16. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology
  17. 17. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Terminology
  18. 18. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Agenda What are we using Groovy for at Spring Cloud? Quick introduction to Distributed Tracing Why Gradle made it possible to test Spring Cloud? How we’re testing with Spock? DEMO
  19. 19. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? What we wanted to achieve: apart from having good unit / integration tests we wanted to see all building blocks working together we didn’t want to write different test apps for different libraries we wanted to write a solution that could test the libs on Cloud Foundry (PaaS by Pivotal) we wanted to prove that Spring Cloud’s Service Discovery integration is all about changing jars and configs
  20. 20. @MGrzejszczak @gr8day_warsaw #GR8DayWAW
  21. 21. @MGrzejszczak @gr8day_warsaw #GR8DayWAW
  22. 22. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? What do we want to test? service discovery is working - apps can talk to each other via RestTemplate via Feign Sleuth is working proper spans were created trace information got propagated
  23. 23. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? change the apps building blocks by properties:
  24. 24. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? package apps with desired building blocks ./gradlew clean build --parallel -DWHAT_TO_TEST=CONSUL ./gradlew clean build --parallel -DWHAT_TO_TEST=EUREKA ./gradlew clean build --parallel -DWHAT_TO_TEST=SLEUTH
  25. 25. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? create Dockerfiles by executing a closure
  26. 26. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? clear separation of configurations
  27. 27. @MGrzejszczak @gr8day_warsaw #GR8DayWAW WhyGradlemadeitpossibletotestSpringCloud? $ ./runAcceptanceTests.sh USAGE: You can use the following options: -t|--whattotest - define what you want to test (e.g. SLEUTH, ZOOKEEPER) -v|--version - which version of BOM do you want to use? Defaults to Brixton snapshot -h|--healthhost - what is your health host? where is docker? defaults to localhost -l|--numberoflines - how many lines of logs of your app do you want to print? Defaults to 1000 -r|--reset - do you want to reset the git repo of brewery? Defaults to "no" -k|--killattheend - should kill all the running apps at the end of execution? Defaults to "no" -n|--killnow - should not run all the logic but only kill the running apps? Defaults to "no" -x|--skiptests - should skip running of e2e tests? Defaults to "no" -s|--skipbuilding - should skip building of the projects? Defaults to "no" -c|--cloudfoundry - should run tests for cloud foundry? Defaults to "no" -o|--deployonlyapps - should deploy only the brewery business apps instead of the infra too? Defaults to "no" -d|--skipdeployment - should skip deployment of apps? Defaults to "no"
  28. 28. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Agenda What are we using Groovy for at Spring Cloud? Quick introduction to Distributed Tracing Why Gradle made it possible to test Spring Cloud? How we’re testing with Spock? DEMO
  29. 29. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Howwe’retestingwithSpock? we wanted to run same tests for Cloud Foundry and locally run the same tests with different libraries used only execute related tests
  30. 30. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Howwe’retestingwithSpock? @Requires({ TestConditions.SLEUTH() }) class SleuthBreweryAcceptanceSpec extends AbstractBreweryAcceptanceSpec { @Unroll def 'should successfully pass Trace Id via [#communicationType] and processId [#referenceProcessId]'() { given: RequestEntity requestEntity = an_order_for_all_ingredients_with_process_id(referenceProcessId, communicationType) when: 'the presenting service has been called with all ingredients' presenting_service_has_been_called(requestEntity) then: 'eventually beer will be brewed with same Trace-Id as the first request' beer_has_been_brewed_for_process_id(referenceProcessId) and: 'entry will be present in Zipkin' entry_for_trace_id_is_present_in_Zipkin(referenceProcessId) where: communicationType << [CommunicationType.REST_TEMPLATE, CommunicationType.FEIGN] referenceProcessId = Span.idToHex(new Random().nextLong()) } }
  31. 31. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Howwe’retestingwithSpock? static final Closure<Boolean> SLEUTH = { return whatToTestSystemPropMatchesAny( [WhatToTest.SLEUTH, WhatToTest.SLEUTH_STREAM] ) }
  32. 32. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Howwe’retestingwithSpock?
  33. 33. @MGrzejszczak @gr8day_warsaw #GR8DayWAW
  34. 34. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Agenda What are we using Groovy for at Spring Cloud? Quick introduction to Distributed Tracing Why Gradle made it possible to test Spring Cloud? How we’re testing with Spock? DEMO
  35. 35. @MGrzejszczak @gr8day_warsaw #GR8DayWAW DEMO
  36. 36. @MGrzejszczak @gr8day_warsaw #GR8DayWAW Summary Gradle allowed to create highly customizable project just by changing a property With Groovy and Spock we’ve managed to create a test setup that is readable and platform-independant Even though they are hard to debug - with E2E we’ve managed to find quite a few bugs already
  37. 37. @MGrzejszczak @gr8day_warsaw #GR8DayWAW ThankYou! Sleuth Repo & Docs: https://github.com/spring-cloud/spring-cloud-sleuth http://cloud.spring.io/spring-cloud-sleuth/spring-cloud-sleuth.html The Brewery https://github.com/spring-cloud-samples/brewery Rationale behind E2E tests https://spring.io/blog/2016/01/04/testing-spring-cloud-projects

×