Giter Club home page Giter Club logo

Comments (6)

outofcoffee avatar outofcoffee commented on July 20, 2024 1

Hi @LukasKnuth, thank you for reporting this.

Sorry to hear you had an issue with the healthcheck. This was fixed in v0.34.0 of the CLI, which was released in Imposter 3.31.6, released on 26/10/23.

Using current build:

$ docker ps
CONTAINER ID   IMAGE                         COMMAND                  CREATED          STATUS          PORTS                              NAMES
d89a494d4d1d   outofcoffee/imposter:3.36.0   "java -classpath /op…"   14 seconds ago   Up 13 seconds   0.0.0.0:8080->8080/tcp, 8443/tcp   peaceful_carson

$ docker exec -it d89 imposter list -x
| ID | NAME | PORT | HEALTH  |
|----|------|------|---------|
|  1 | java | 8080 | healthy |

$ echo $?
0

For completeness - an unhealthy example:

$ docker exec -it $( docker ps -q ) imposter list -x ; echo $?
ERRO[0000] healthcheck request failed for mock: healthcheck request failed for mock at http://localhost:8080/system/status: Get "http://localhost:8080/system/status": dial tcp 127.0.0.1:8080: connect: connection refused

| ID | NAME | PORT |  HEALTH   |
|----|------|------|-----------|
|  1 | java | 8080 | unhealthy |

1

from imposter.

outofcoffee avatar outofcoffee commented on July 20, 2024

Hi @LukasKnuth, thanks for raising this.

Yes, you can use the /system/status healthcheck endpoint which returns HTTP 200 when the server is up.

For additional binaries inside the container, here's an example of a custom Docker image https://github.com/outofcoffee/imposter/blob/main/examples/docker/Dockerfile

☝️ This example extends from the Java base image so has its various userspace tools available (and more you can install with the package manager).

from imposter.

outofcoffee avatar outofcoffee commented on July 20, 2024

For this part of your question:

Would you be open to adding a CLI option to the server to check if its up and ready?

You should be able to use this command with the CLI:

imposter list --exit-code-health

You can also use the short form of the --exit-code-health argument, -x
More info here.

This sets the exit code based on mock health.

Example

$ imposter list -x ; echo $?
| ID | NAME | PORT | HEALTH |
|----|------|------|--------|
1

☝️ Returns code 1 as no mocks running.

$ imposter list -x ; echo $?
|      ID      |     NAME     | PORT | HEALTH  |
|--------------|--------------|------|---------|
| d5755b211011 | /brave_mayer | 8080 | healthy |
0

☝️ Returns code 0 as a healthy mock running.

from imposter.

LukasKnuth avatar LukasKnuth commented on July 20, 2024

Nice, thanks for getting back to me. I wasn't aware that this existed already, thats great!

from imposter.

LukasKnuth avatar LukasKnuth commented on July 20, 2024

I tested it with my setup now and for me, this doesn't seem to work as expected:

$ docker exec e2e-apiv1-1 imposter list -x
| ID | NAME | PORT | HEALTH  |
|----|------|------|---------|
|  1 | java |    0 | unknown |
$ echo $?
1

I use the openapi plugin for this. Everything in the mock works as expected, just the list returns the unknown health status. Do I need to add any additional information to the configuration for imposter ls to pick it up and/or it's health?

from imposter.

rnestler avatar rnestler commented on July 20, 2024

If somebody ends here via search: One can configure a healthcheck with docker-compose like this:

    healthcheck:
      test: ["CMD", "imposter", "list", "-x"]
      interval: 3s
      timeout: 10s
      retries: 5

from imposter.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.