Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Dockerfile and docker-compose.yml to run example code #635

Merged
merged 23 commits into from
Apr 23, 2020

Conversation

andrewhsu
Copy link
Member

This PR adds a docker compose configuration file to help a new user compile and run the example code quickly.

To build the example http server and client:

$ docker-compose build http-server http-client

Bringing up the http-server and http-client services, the server will stay running but the client will exit after doing its thing:

$ docker-compose up http-server http-client
Creating opentelemetry-go_http-server_1 ... done
Creating opentelemetry-go_http-client_1 ... done
Attaching to opentelemetry-go_http-server_1, opentelemetry-go_http-client_1
http-server_1  | {      
http-server_1  |        "SpanContext": {
http-server_1  |                "TraceID": "7d8ced232b1f47ba7ddf5000723a3247",
http-server_1  |                "SpanID": "44cd137e23da9839",
...
http-server_1  |        "ChildSpanCount": 0,
http-server_1  |        "Resource": null
http-server_1  | }      
http-client_1  | Sending request...
http-client_1  | {
http-client_1  |        "SpanContext": {
http-client_1  |                "TraceID": "7d8ced232b1f47ba7ddf5000723a3247",
http-client_1  |                "SpanID": "5c66984910c1f23f",
...
http-client_1  |        "ChildSpanCount": 4,
http-client_1  |        "Resource": null
http-client_1  | }      
http-client_1  | Response Received: Hello, world!
http-client_1  |
http-client_1  |
http-client_1  |
http-client_1  | Waiting for few seconds to export spans ...
http-client_1  | 
http-client_1  | Inspect traces on stdout
opentelemetry-go_http-client_1 exited with code 0
^CGracefully stopping... (press Ctrl+C again to force)
Stopping opentelemetry-go_http-server_1 ... done

Building the zipkin client example:

$ docker-compose build zipkin-client

Bringing up the zipkin-collector and zipkin-client services, the server will stay running with an exposed port 9411 for the web UI while the client will exit shortly after it does its thing:

$ docker-compose up zipkin-collector zipkin-client
Creating network "opentelemetry-go_example" with the default driver
Creating opentelemetry-go_zipkin-collector_1 ... done
Creating opentelemetry-go_zipkin-client_1    ... done
Attaching to opentelemetry-go_zipkin-collector_1, opentelemetry-go_zipkin-client_1
zipkin-client_1     | sleep for 1s waiting for zipkin-collector to become available
zipkin-collector_1  |
zipkin-collector_1  |                   oo
zipkin-collector_1  |                  oooo
...
zipkin-client_1     | sleep for 1s waiting for zipkin-collector to become available
zipkin-collector_1  | 2020-04-12 22:47:23:457 [main] INFO SystemInfo - Hostname: 948d8d041ec9 (from /proc/sys/kernel/hostname)
zipkin-collector_1  | 2020-04-12 22:47:23:806 [armeria-boss-http-*:9411] INFO Server - Serving HTTP at /0.0.0.0:9411 - http://127.0.0.1:9411/
zipkin-collector_1  | 2020-04-12 22:47:23:808 [main] INFO ArmeriaAutoConfiguration - Armeria server started at ports: {/0.0.0.0:9411=ServerPort(/0.0.0.0:9411, [http])}
zipkin-collector_1  | 2020-04-12 22:47:23:828 [main] INFO ZipkinServer - Started ZipkinServer in 2.162 seconds (JVM running for 2.859)
zipkin-client_1     | zipkin-example2020/04/12 22:47:24 /go/pkg/mod/go.opentelemetry.io/otel/exporters/trace/[email protected]/zipkin.go:113: about to send a POST request to http://zipkin-collector:9411/api/v2/spans with body [{"timestamp":1586731644328456,"duration":6018,"traceId":"eb4c0238dc9118146e9cfff8be43648f","id":"2a36ff83e2578da0","parentId":"ee46c84a752f61b9","name":"bar","tags":{"ot.status_code":"OK","ot.status_description":""}}]
zipkin-collector_1  | 2020-04-12 22:47:24:493 [armeria-common-worker-epoll-2-2] INFO JavaVersionSpecific - Using the APIs optimized for: Java 9+
opentelemetry-go_zipkin-client_1 exited with code 0

Screenshot of the zipkin UI with traceId eb4c0238dc9118146e9cfff8be43648f that was generated when running the example:
Screen Shot 2020-04-12 at 3 48 47 PM

Dockerfile Outdated Show resolved Hide resolved
Dockerfile Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
example/http/client/client.go Outdated Show resolved Hide resolved
example/zipkin/main.go Outdated Show resolved Hide resolved
Copy link
Member

@krnowak krnowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick, otherwise looks good.

Dockerfile Outdated Show resolved Hide resolved
@andrewhsu andrewhsu force-pushed the example-with-docker branch from 3975102 to a0eb377 Compare April 17, 2020 02:25
@andrewhsu
Copy link
Member Author

@krnowak @MrAlias @Aneurysm9 i believe this PR should be good to go now. has doc updates as well.

@andrewhsu andrewhsu requested a review from krnowak April 17, 2020 22:25
andrewhsu and others added 15 commits April 19, 2020 15:10
Multi-stage Dockerfile with targets for building example http server and
client.

  $ docker build --tag the-server --target example-http-server .
  $ docker build --tag the-client --target example-http-client .

Signed-off-by: Andrew Hsu <[email protected]>
This docker compose configuration file will help a new user to compile
and run the example code quickly. Uses the Dockerfile to build images
with compiled examples.

  $ docker-compose build http-server http-client
  $ docker-compose up http-server http-client

Signed-off-by: Andrew Hsu <[email protected]>
For building the example zipkin client:

  $ docker build --tag zipkin-client --target example-zipkin-client .

Signed-off-by: Andrew Hsu <[email protected]>
Services to run the zipkin client along with a zipkin collector:

  $ docker-compose build zipkin-client
  $ docker-compose up zipkin-collector zipkin-client

Since the zipkin collector takes a few seconds before it is ready to
receive traces, I added a simple retry loop to the client command.

The collector service exposes port 9411 so user can visit
http//localhost:9411/ to see the trace sent to the collector. Be sure to
search by the trace id logged by the client.

Signed-off-by: Andrew Hsu <[email protected]>
  $ ./client -h
  Usage of ./client:
    -server string
          server url (default "http://localhost:7777/hello")

Signed-off-by: Andrew Hsu <[email protected]>
  $ ./zipkin -h
  Usage of ./zipkin:
    -zipkin string
          zipkin url (default "http://localhost:9411/api/v2/spans")

Signed-off-by: Andrew Hsu <[email protected]>
With instructions on how to use docker-compose to run the example.

Signed-off-by: Andrew Hsu <[email protected]>
With instructions on how to use docker-compose to run the example.

Signed-off-by: Andrew Hsu <[email protected]>
@andrewhsu andrewhsu force-pushed the example-with-docker branch from 482714b to 979d93f Compare April 19, 2020 22:14
@andrewhsu
Copy link
Member Author

@Aneurysm9 @krnowak @MrAlias @jmacd thanks for the approvals. Looks like #644 merged before this PR and caused conflict so I rebased and force pushed. Just a simple conflict resolution in initTracer.

example/http/Dockerfile Outdated Show resolved Hide resolved
example/http/Dockerfile Outdated Show resolved Hide resolved
example/http/Dockerfile Outdated Show resolved Hide resolved
example/zipkin/Dockerfile Outdated Show resolved Hide resolved
example/zipkin/Dockerfile Outdated Show resolved Hide resolved
@andrewhsu
Copy link
Member Author

@krnowak i've accepted all of your change requests after i verified stuff still works. PR is ready for merge.

@krnowak
Copy link
Member

krnowak commented Apr 23, 2020

@andrewhsu: LGTM. But it looks like either github has problems with receiving reports CI or CI has problems with sending reports to github.

@jmacd jmacd merged commit 6402598 into open-telemetry:master Apr 23, 2020
@andrewhsu andrewhsu deleted the example-with-docker branch April 24, 2020 21:17
@pellared pellared added this to the untracked milestone Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants