Skip to content

A Game of Life example that demonstrates the use case of OpenCensus with gRPC.

Notifications You must be signed in to change notification settings

songy23/game-of-life-demo

Repository files navigation

OpenCensus Game of Life Codelab

This codelab demonstrates OpenCensus with a simple client/server Java example based on Conway's Game of Life (abbreviated as Life for the remainder of this Codelab). You will learn how to define OpenCensus tags, measures and views, how to add tags to the Life application, how to record stats against current tag context, and how to view and understand the stats collected against those tags.

The Life application used in this Codelab consists of a Life client and a Life server.

The Life client consists of three two-dimensional matrices: 8x8, 16x16, and 32x32. Each of the cells in the matrices can be alive or dead depending on some rules. The client takes in the number of RPC calls from the user and sends that many requests to the server to calculate the alive/dead cell configuration for the matrices. The server performs the calculations and sends the response back to the client to display the results.

Prerequisites

  1. Install Bazel.
  2. Install Protobuf Compiler.
  3. Get yourself familar with OpenCensus basics.
  4. Optionally, get yourself familar with gRPC basics.
  5. Optionally, set up a Google Cloud project and enable Stackdriver Monitoring, if you would also like to view the stats on Stackdriver Monioring dashboard.

Build and Run the Example

Gradle

$ ./gradlew installDist
$ ./build/install/opencensus-game-of-life-example/bin/GameOfLifeServer SERVER_PORT SERVER_ZPAGE_PORT CLOUD_PROJECT_ID PROMETHEUS_PORT
$ ./build/install/opencensus-game-of-life-example/bin/GameOfLifeClient SERVER_PORT CLIENT_ZPAGE_PORT CLOUD_PROJECT_ID

Maven

$ mvn package appassembler:assemble
$ ./target/appassembler/bin/GameOfLifeServer SERVER_PORT SERVER_ZPAGE_PORT CLOUD_PROJECT_ID PROMETHEUS_PORT
$ ./target/appassembler/bin/GameOfLifeClient SERVER_PORT CLIENT_ZPAGE_PORT CLOUD_PROJECT_ID

Bazel

$ bazel build :all
$ bazel-bin/bazel-bin/game-of-life-server SERVER_PORT SERVER_ZPAGE_PORT CLOUD_PROJECT_ID PROMETHEUS_PORT
$ bazel-bin/bazel-bin/game-of-life-client SERVER_PORT CLIENT_ZPAGE_PORT CLOUD_PROJECT_ID

By default,

  • SERVER_PORT is 3000
  • SERVER_ZPAGE_PORT is 9000
  • CLIENT_ZPAGE_PORT is 9001
  • CLOUD_PROJECT_ID is null (which means no stats/spans will be exported to Stackdriver)
  • PROMETHEUS_PORT is 10000

To view the game of life board and play the game, go to:
localhost:CLIENT_ZPAGE_PORT/clientz

Detailed Explanations on the Demo Code

TODO

View Stats and Spans on ZPages

To view stats and/or spans on client side, go to:
localhost:CLIENT_ZPAGE_PORT/rpcz
localhost:CLIENT_ZPAGE_PORT/statsz
localhost:CLIENT_ZPAGE_PORT/tracez

To view stats and/or spans on server side, go to:
localhost:SERVER_ZPAGE_PORT/rpcz
localhost:SERVER_ZPAGE_PORT/statsz
localhost:SERVER_ZPAGE_PORT/tracez

View Stats and Spans on Stackdriver Dashboard

If you specified a valid CLOUD_PROJECT_ID and have the appropriate Google credentials set, stats from the Life client and server will be exported to Stackdriver Monitoring, and spans will be exported to Stackdriver Trace.

Go to Stackdriver Monitoring main page, and follow the instructions to create a dashboard and charts. Then you can view stats from Life application on those charts.

View Stats on Prometheus Metrics page

To view both server and client stats on Prometheus metrics page, go to:
localhost:PROMETHEUS_PORT/metrics

About

A Game of Life example that demonstrates the use case of OpenCensus with gRPC.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published