Skip to content

Instantly share code, notes, and snippets.

@tjquinno
Last active August 25, 2020 23:09
Show Gist options
  • Save tjquinno/70a2e62dbae2cf42c48a9a7eea8201c6 to your computer and use it in GitHub Desktop.
Save tjquinno/70a2e62dbae2cf42c48a9a7eea8201c6 to your computer and use it in GitHub Desktop.
MP metrics, health, REST client, and OpenAPI demo

Overview

There will be two projects. One is built and started ahead of time and has a very simple API:

  • a GET that accepts a String and returns it upper-cased after waiting an amount of time (initialed to a delay of 0),
  • a PUT that accepts a new delay time in ms.

Note that this app is unrealistically simple but illustrates service-calling-service and health in the main app.

The other project is the normal greeting one from helidon init with:

  • an added liveness check that pings the other project’s up-case endpoint and reports “not ready” if it takes more than 200 ms to respond, and
  • the two greet methods updated to invoke the up-case endpoint in the other app.

Ahead of time:

  1. Download and set up the Helidon CLI.
  2. Create, build, and run the upcase app.
  3. Prepare a Prometheus config file to work with the main app.
scrape_configs:
  - job_name: 'helidon'
    scrape_interval: 5s
    metrics_path: '/metrics'
    static_configs:
      - targets: ['docker.for.mac.host.internal:8080']

During the demo:

  1. Show one slide with a schematic of the moving parts:

    • main greeting app
    • up-case app
    • Prometheus
  2. Set up Prometheus.

    1. Show the Prometheus config file, then start Prometheus:

      docker run \
          -p 9090:9090 \
          -v ~/prometheus.yml:/etc/prometheus/prometheus.yml \
          --name prom \
          --rm \
          prom/prometheus
      
  3. Use the Helidon CLI. (https://helidon.io/docs/v2/#/mp/cli/01_cli)

    1. Show the Helidon CLI download and set-up commands:

      curl -O https://helidon.io/cli/latest/darwin/helidon
      chmod +x ./helidon
      sudo mv ./helidon /usr/local/bin/
      
    2. Generate the project: helidon init

    3. Open the IDE and take a quick look at the generated endpoints.

    4. Start dev loop:

      cd myproject
      helidon dev
      
  4. Show the app before any changes:

    1. Access the app briefly to see it working.
    2. Show metrics and health replies.
    3. Show OpenAPI document briefly.
  5. Use the IDE to add an app metric to the two GET methods reusing the same counter.

    1. Show the dev loop’s response to the changes.
    2. Access the greeting endpoint using curl.
    3. Access Prometheus to see the new metric.
  6. Use the IDE to add access to the up-case service.

    1. Add a private method that accepts a String and uses the REST client to contact the up-case service and returns the String in the reply.
    2. Revise the two greeting methods to invoke that new private method.
    3. Add a liveness check that invokes the up-case endpoint and times the delay, reporting UP if < 200 ms and DOWN otherwise.
  7. Show the updated app’s behavior:

    1. Access the greeting endpoint using curl. Note the up-cased response.
    2. Access /health/live. Note the UP result.
  8. Change the delay in the up-case app using curl PUT:

    curl -i -X PUT -H "Content-Type: application/json"  -d '{ "delay" : 500}' http://localhost:8084/upcase
    
  9. Show the app’s health:

    1. Access /health/live. Note the DOWN result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment