Lab: find the cause in the logs

Verified lab · 25 min · Module 2, lesson 4 of 530 min left in this module

Module 2 · LogsLesson 4 of 5

Self-checked for now. Automatic checking arrives with sign-in; until then, tick off each item under Check your work yourself.

Goal: Fix a service that crashes on start, using only what its logs tell you.

You need csph signed in, with learn and lab as your defaults (lesson 5.1.1), and room for one Flex spherelet.

  1. Deploy the shop

    csph deploy --image quay.io/computesphere/learn-shop-api:1.4.0 \
      --name shop-api --port 8080 --no-wait
    

    --no-wait hands your terminal back instead of waiting for a service that won't start.

    You should seecsph returns without waiting, and shop-api shows Deploying in the console.

  2. Read the deploy log

    Open shop-api, choose the Logs tab, then Deploy.

    The status can still say Running. A Complete chip on the log means it stopped fetching: reload the page for new events.

    You should seewithin a few minutes, Restarting repeatedly: The service is restarting repeatedly.

  3. Find why in the runtime log

    Choose Runtime and search for fatal, or run:

    csph logs shop-api --search fatal
    

    Check yourself

    Why does shop-api keep crashing?

    You should seethe same fatal line, once per crash, ending "missing":"SIGNING_KEY"

  4. Add the secret

    In Settings, Environment variables, choose Edit, then the Secrets tab. Add SIGNING_KEY = demo-not-a-real-key-0000, Save, and choose Save & redeploy.

    You should seeshop-api shows Running within a few minutes.

  5. Confirm it started

    csph logs shop-api --kind deploy
    csph logs shop-api --search ready
    

    You should seeLive at the top of the deploy log, and "ready: catalog loaded, /healthz answers 200" in the runtime log.

  6. Call it

    The URL is on shop-api's page in the console:

    curl https://<your-shop-api-url>/healthz
    

    Keep shop-api: later modules use it.

    You should see{"status":"ok"}

Check your work

  • If this doesn't pass

    The name is case-sensitive, and it belongs on the Secrets tab, not General.

  • If this doesn't pass

    Saved with Save only? Choose Redeploy on shop-api. Still crashing? Search the runtime log for fatal again: a different line means a different cause.

  • If this doesn't pass

    Wait for Running first. If it's Running but doesn't answer, wait a minute and try again.

  • If this doesn't pass

    Read the fatal line in step 3: its missing field names the variable.

In the docs