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 example for Jaeger. #16

Merged
merged 4 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ RUN set -x \
&& git clone https://github.com/opentracing/opentracing-cpp.git \
&& cd opentracing-cpp \
&& mkdir .build && cd .build \
&& cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF .. \
&& make && make install \
&& cd "$tempDir" \
## Build zipkin-cpp-opentracing
Expand All @@ -48,38 +49,32 @@ RUN set -x \
&& cmake -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. \
&& make && make install \
&& cd "$tempDir" \
### Build Jaeger cpp-client
&& git clone https://github.com/jaegertracing/cpp-client.git jaeger-cpp-client \
&& cd jaeger-cpp-client \
&& mkdir .build && cd .build \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DJAEGERTRACING_WITH_YAML_CPP=OFF .. \
&& make && make install \
&& export HUNTER_INSTALL_DIR=$(cat _3rdParty/Hunter/install-root-dir) \
&& cd "$tempDir" \
### Build gRPC
&& git clone -b v1.4.x https://github.com/grpc/grpc \
&& cd grpc \
&& git submodule update --init \
&& make HAS_SYSTEM_PROTOBUF=false && make install \
# && mkdir .build && cd .build \
# && cmake -DCMAKE_BUILD_TYPE=Release -DgRPC_ZLIB_PROVIDER=package .. \
&& make && make install \
&& cd "$tempDir" \
### Build lightstep-tracer-cpp
# && apt-get install --no-install-recommends --no-install-suggests -y \
# libprotobuf-dev \
# protobuf-compiler \
&& git clone https://github.com/lightstep/lightstep-tracer-cpp.git \
&& cd lightstep-tracer-cpp \
&& mkdir .build && cd .build \
&& cmake -DBUILD_SHARED_LIBS=1 -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF .. \
&& make && make install \
&& cd "$tempDir" \
### Build Jaeger cpp-client
&& git clone https://github.com/jaegertracing/cpp-client.git jaeger-cpp-client \
&& cd jaeger-cpp-client \
&& mkdir .build && cd .build \
&& cmake -DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=OFF \
-DJAEGERTRACING_WITH_YAML_CPP=OFF .. \
&& make && make install \
&& export HUNTER_INSTALL_DIR=$(cat _3rdParty/Hunter/install-root-dir) \
&& cd "$tempDir" \
### Get nginx-opentracing source
### Build nginx-opentracing modules
&& git clone https://github.com/opentracing-contrib/nginx-opentracing.git \
## Build nginx-opentracing modules
&& NGINX_VERSION=`nginx -v 2>&1` && NGINX_VERSION=${NGINX_VERSION#*nginx/} \
&& echo "deb-src http://nginx.org/packages/mainline/debian/ stretch nginx" >> /etc/apt/sources.list \
&& apt-get update \
Expand All @@ -102,10 +97,11 @@ RUN set -x \
&& cp objs/ngx_http_lightstep_module.so $NGINX_MODULES_PATH/ \
&& cp objs/ngx_http_jaeger_module.so $NGINX_MODULES_PATH/ \
# if we have leftovers from building, let's purge them (including extra, unnecessary build deps)
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
fi
&& rm -rf $HOME/.hunter \
&& if [ -n "$tempDir" ]; then \
apt-get purge -y --auto-remove \
&& rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; \
fi

# forward request and error logs to docker log collector
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
Expand Down
52 changes: 52 additions & 0 deletions example/hotrod/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM rnburn/nginx-opentracing

WORKDIR /app
ADD . /app
RUN set -x \
# new directory for storing sources and .deb files
&& tempDir="$(mktemp -d)" \
&& chmod 777 "$tempDir" \
\
# save list of currently-installed packages so build dependencies can be cleanly removed later
&& savedAptMark="$(apt-mark showmanual)" \
\
# set up go
&& apt-get update \
&& apt-get install --no-install-recommends --no-install-suggests -y \
git \
ca-certificates \
software-properties-common \
wget \
curl \
&& wget https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz \
&& tar -xvf go1.8.3.linux-amd64.tar.gz \
&& mv go $tempDir \
&& export GOROOT=$tempDir/go \
&& export GOPATH=$tempDir/gopath \
&& mkdir -p $GOPATH/bin \
&& export PATH=$GOPATH/bin:$GOROOT/bin:$PATH \
# install glide
&& curl https://glide.sh/get | sh \
# build the hotrod demo
&& mkdir -p $GOPATH/src/github.com/rnburn/ \
&& mv /app/hotrod $GOPATH/src/github.com/rnburn/hotrod-docker \
&& cd $GOPATH/src/github.com/rnburn/hotrod-docker \
&& glide install \
&& go build -o hotrod \
&& mv hotrod /app/hotrod \
&& mkdir -p /app/services/frontend/web_assets \
&& cp services/frontend/web_assets/index.html /app/services/frontend/web_assets/index.html \
# reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
# (which is done after we install the built packages so we don't have to redownload any overlapping dependencies)
&& apt-mark showmanual | xargs apt-mark auto > /dev/null \
&& { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; } \
\
# purge leftovers from building them (including extra, unnecessary build deps)
&& apt-get purge -y --auto-remove \
&& rm -rf "$tempDir"

EXPOSE 8080

STOPSIGNAL SIGTERM

CMD ["/app/start.sh"]
14 changes: 14 additions & 0 deletions example/hotrod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
An OpenTracing example demonstrating usage of the nginx-opentracing docker
image with jaeger. It builds on Jaeger's HotROD example (see blog post
[Take OpenTracing for a HotROD ride](https://medium.com/opentracing/take-opentracing-for-a-hotrod-ride-f6e3141f7941)),
but inserts nginx as a load balancer for the HotROD services.

Use these commands to run:
```bash
docker build -t nginx-example-hotrod .
docker run -d -e COLLECTOR_ZIPKIN_HTTP_PORT=9411 -p5775:5775/udp -p6831:6831/udp -p6832:6832/udp \
-p5778:5778 -p16686:16686 -p14268:14268 -p9411:9411 --name jaeger jaegertracing/all-in-one:latest
docker run -d -p 8080:80 --link jaeger:jaeger nginx-example-hotrod
```
Visit http://localhost:8080 to interact with the demo and http://localhost:16686
to view the traces in Jaeger.
35 changes: 35 additions & 0 deletions example/hotrod/hotrod/cmd/all.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import "github.com/spf13/cobra"

// allCmd represents the all command
var allCmd = &cobra.Command{
Use: "all",
Short: "Starts all services",
Long: `Starts all services.`,
Run: func(cmd *cobra.Command, args []string) {
logger.Info("Starting all services")
go customerCmd.RunE(customerCmd, args)
go driverCmd.RunE(driverCmd, args)
go routeCmd.RunE(routeCmd, args)
frontendCmd.RunE(frontendCmd, args)
},
}

func init() {
RootCmd.AddCommand(allCmd)
}
58 changes: 58 additions & 0 deletions example/hotrod/hotrod/cmd/customer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"net"
"strconv"

"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/rnburn/hotrod-docker/pkg/log"
"github.com/rnburn/hotrod-docker/pkg/tracing"
"github.com/rnburn/hotrod-docker/services/customer"
)

// customerCmd represents the customer command
var customerCmd = &cobra.Command{
Use: "customer",
Short: "Starts Customer service",
Long: `Starts Customer service.`,
RunE: func(cmd *cobra.Command, args []string) error {
logger := log.NewFactory(logger.With(zap.String("service", "customer")))
server := customer.NewServer(
net.JoinHostPort(customerOptions.serverInterface, strconv.Itoa(customerOptions.serverPort)),
tracing.Init("customer", metricsFactory.Namespace("customer", nil), logger),
metricsFactory,
logger,
)
return server.Run()
},
}

var (
customerOptions struct {
serverInterface string
serverPort int
}
)

func init() {
RootCmd.AddCommand(customerCmd)

customerCmd.Flags().StringVarP(&customerOptions.serverInterface, "bind", "", "127.0.0.1", "interface to which the Customer server will bind")
customerCmd.Flags().IntVarP(&customerOptions.serverPort, "port", "p", 8081, "port on which the Customer server will listen")
}
58 changes: 58 additions & 0 deletions example/hotrod/hotrod/cmd/driver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"net"
"strconv"

"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/rnburn/hotrod-docker/pkg/log"
"github.com/rnburn/hotrod-docker/pkg/tracing"
"github.com/rnburn/hotrod-docker/services/driver"
)

// driverCmd represents the driver command
var driverCmd = &cobra.Command{
Use: "driver",
Short: "Starts Driver service",
Long: `Starts Driver service.`,
RunE: func(cmd *cobra.Command, args []string) error {
logger := log.NewFactory(logger.With(zap.String("service", "driver")))
server := driver.NewServer(
net.JoinHostPort(driverOptions.serverInterface, strconv.Itoa(driverOptions.serverPort)),
tracing.Init("driver", metricsFactory.Namespace("driver", nil), logger),
metricsFactory,
logger,
)
return server.Run()
},
}

var (
driverOptions struct {
serverInterface string
serverPort int
}
)

func init() {
RootCmd.AddCommand(driverCmd)

driverCmd.Flags().StringVarP(&driverOptions.serverInterface, "bind", "", "127.0.0.1", "interface to which the driver server will bind")
driverCmd.Flags().IntVarP(&driverOptions.serverPort, "port", "p", 8082, "port on which the driver server will listen")
}
57 changes: 57 additions & 0 deletions example/hotrod/hotrod/cmd/frontend.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"net"
"strconv"

"github.com/spf13/cobra"
"go.uber.org/zap"

"github.com/rnburn/hotrod-docker/pkg/log"
"github.com/rnburn/hotrod-docker/pkg/tracing"
"github.com/rnburn/hotrod-docker/services/frontend"
)

// frontendCmd represents the frontend command
var frontendCmd = &cobra.Command{
Use: "frontend",
Short: "Starts Frontend service",
Long: `Starts Frontend service.`,
RunE: func(cmd *cobra.Command, args []string) error {
logger := log.NewFactory(logger.With(zap.String("service", "frontend")))
server := frontend.NewServer(
net.JoinHostPort(frontendOptions.serverInterface, strconv.Itoa(frontendOptions.serverPort)),
tracing.Init("frontend", metricsFactory.Namespace("frontend", nil), logger),
logger,
)
return server.Run()
},
}

var (
frontendOptions struct {
serverInterface string
serverPort int
}
)

func init() {
RootCmd.AddCommand(frontendCmd)

frontendCmd.Flags().StringVarP(&frontendOptions.serverInterface, "bind", "", "", "interface to which the frontend server will bind")
frontendCmd.Flags().IntVarP(&frontendOptions.serverPort, "port", "p", 8080, "port on which the frontend server will listen")
}
Loading