forked from open-telemetry/opentelemetry-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currency Service using C++ (open-telemetry#189)
* Saving incremental changes * Saved the draft * Added convert function * Added some more changes * Updated more changes * More changes * Removed js code * Final changes * Currency Service in C++ * Cleaned up license * Removed trailing space * Incorporated review comments * Updated sanity failure * Resolved md error * Resolved md error Co-authored-by: Austin Parker <[email protected]> Co-authored-by: Carter Socha <[email protected]>
- Loading branch information
1 parent
410dd26
commit c66fd34
Showing
12 changed files
with
678 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
cmake_minimum_required(VERSION 3.1) | ||
project(currency-service) | ||
|
||
find_package(Protobuf) | ||
find_package(gRPC) | ||
|
||
set(PROTO_PATH "${CMAKE_CURRENT_SOURCE_DIR}/proto") | ||
set(GENERATED_PROTOBUF_PATH "${CMAKE_BINARY_DIR}/generated/proto") | ||
set(GENERATED_HEALTH_PROTOBUF_PATH "${GENERATED_PROTOBUF_PATH}/grpc/health/v1") | ||
|
||
file(MAKE_DIRECTORY "${GENERATED_PROTOBUF_PATH}") | ||
|
||
set(DEMO_PROTO "${PROTO_PATH}/demo.proto") | ||
set(DEMO_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/demo.pb.cc") | ||
set(DEMO_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/demo.pb.h") | ||
set(DEMO_GRPC_PB_CPP_FILE "${GENERATED_PROTOBUF_PATH}/demo.grpc.pb.cc") | ||
set(DEMO_GRPC_PB_H_FILE "${GENERATED_PROTOBUF_PATH}/demo.grpc.pb.h") | ||
set(HEALTH_PROTO "${PROTO_PATH}/grpc/health/v1/health.proto") | ||
set(HEALTH_PB_CPP_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.pb.cc") | ||
set(HEALTH_PB_H_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.pb.h") | ||
set(HEALTH_GRPC_PB_CPP_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.grpc.pb.cc") | ||
set(HEALTH_GRPC_PB_H_FILE "${GENERATED_HEALTH_PROTOBUF_PATH}/health.grpc.pb.h") | ||
|
||
foreach(IMPORT_DIR ${PROTOBUF_IMPORT_DIRS}) | ||
list(APPEND PROTOBUF_INCLUDE_FLAGS "-I${IMPORT_DIR}") | ||
endforeach() | ||
|
||
find_program(gRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) | ||
|
||
add_custom_command( | ||
OUTPUT ${DEMO_PB_H_FILE} | ||
${DEMO_PB_CPP_FILE} | ||
${DEMO_GRPC_PB_CPP_FILE} | ||
${DEMO_GRPC_PB_H_FILE} | ||
${HEALTH_PB_H_FILE} | ||
${HEALTH_PB_CPP_FILE} | ||
${HEALTH_GRPC_PB_CPP_FILE} | ||
${HEALTH_GRPC_PB_H_FILE} | ||
|
||
COMMAND | ||
${PROTOBUF_PROTOC_EXECUTABLE} ARGS "--experimental_allow_proto3_optional" | ||
"--proto_path=${PROTO_PATH}" ${PROTOBUF_INCLUDE_FLAGS} | ||
"--cpp_out=${GENERATED_PROTOBUF_PATH}" | ||
"--grpc_out=generate_mock_code=true:${GENERATED_PROTOBUF_PATH}" | ||
--plugin=protoc-gen-grpc="${gRPC_CPP_PLUGIN_EXECUTABLE}" ${DEMO_PROTO} ${HEALTH_PROTO}) | ||
|
||
message(STATUS "gRPC_CPP_PLUGIN_EXECUTABLE=${gRPC_CPP_PLUGIN_EXECUTABLE}") | ||
|
||
add_library(demo-proto ${DEMO_PB_H_FILE} | ||
${DEMO_PB_CPP_FILE} | ||
${DEMO_GRPC_PB_CPP_FILE} | ||
${DEMO_GRPC_PB_H_FILE} | ||
${HEALTH_PB_H_FILE} | ||
${HEALTH_PB_CPP_FILE} | ||
${HEALTH_GRPC_PB_CPP_FILE} | ||
${HEALTH_GRPC_PB_H_FILE}) | ||
|
||
target_link_libraries(demo-proto gRPC::grpc++ protobuf::libprotobuf) | ||
include_directories("${GENERATED_PROTOBUF_PATH}") | ||
|
||
add_executable(currencyservice src/server.cpp) | ||
add_dependencies(currencyservice demo-proto) | ||
target_link_libraries( | ||
currencyservice demo-proto protobuf::libprotobuf | ||
opentelemetry_resources opentelemetry_trace opentelemetry_common opentelemetry_exporter_otlp_grpc opentelemetry_proto opentelemetry_otlp_recordable gRPC::grpc++) | ||
|
||
add_executable(currencyclient src/client.cpp) | ||
add_dependencies(currencyclient demo-proto) | ||
target_link_libraries( | ||
currencyclient demo-proto protobuf::libprotobuf gRPC::grpc++) | ||
|
||
install(TARGETS currencyservice DESTINATION bin) | ||
install(TARGETS currencyclient DESTINATION bin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,57 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# 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. | ||
|
||
FROM node:16-alpine as base | ||
|
||
FROM base as builder | ||
|
||
# Some packages (e.g. @google-cloud/profiler) require additional | ||
# deps for post-install scripts | ||
RUN apk add --update --no-cache \ | ||
python3 \ | ||
make \ | ||
g++ | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install --only=production | ||
|
||
FROM base | ||
|
||
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.7 && \ | ||
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \ | ||
chmod +x /bin/grpc_health_probe | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY --from=builder /usr/src/app/node_modules ./node_modules | ||
|
||
COPY . . | ||
|
||
EXPOSE 7000 | ||
|
||
ENTRYPOINT [ "node", "--require", "./tracing.js", "server.js" ] | ||
FROM ubuntu:20.04 | ||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
RUN apt-get -y update | ||
RUN apt-get -y upgrade && apt-get -y dist-upgrade | ||
RUN apt-get install -qq -y --ignore-missing \ | ||
build-essential \ | ||
git \ | ||
make \ | ||
pkg-config \ | ||
protobuf-compiler \ | ||
libprotobuf-dev \ | ||
cmake | ||
|
||
# The following arguments would be passed from docker-compose.yml | ||
ARG GRPC_VERSION | ||
ARG OPENTELEMETRY_VERSION | ||
|
||
# Install GRPC | ||
RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v${GRPC_VERSION} \ | ||
https://github.com/grpc/grpc \ | ||
&& cd grpc \ | ||
&& mkdir -p cmake/build \ | ||
&& cd cmake/build \ | ||
&& cmake \ | ||
-DgRPC_INSTALL=ON \ | ||
-DgRPC_BUILD_TESTS=OFF \ | ||
-DCMAKE_BUILD_TYPE=Release \ | ||
-DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \ | ||
-DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \ | ||
-DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ | ||
-DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \ | ||
-DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \ | ||
-DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF \ | ||
../.. \ | ||
&& make -j2 \ | ||
&& make install \ | ||
&& cd ../../.. \ | ||
&& rm -rf grpc | ||
|
||
# install opentelemetry | ||
RUN git clone https://github.com/open-telemetry/opentelemetry-cpp \ | ||
&& cd opentelemetry-cpp/ \ | ||
&& git checkout tags/v${OPENTELEMETRY_VERSION} -b v${OPENTELEMETRY_VERSION} \ | ||
&& git submodule update --init --recursive \ | ||
&& mkdir build \ | ||
&& cd build \ | ||
&& cmake .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF -DWITH_OTLP=ON \ | ||
&& make -j install && cd ../.. && rm -rf opentelemetry-cpp | ||
|
||
COPY . /currencyservice | ||
|
||
RUN cd /currencyservice \ | ||
&& mkdir -p build && cd build \ | ||
&& cmake .. && make -j install | ||
|
||
ENTRYPOINT currencyservice ${PORT} ${OTEL_EXPORTER_OTLP_TRACES_ENDPOINT} ${OTEL_RESOURCE_ATTRIBUTES} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,32 @@ | ||
# Read Me | ||
# Currency Service | ||
|
||
This is a placeholder | ||
The Currency Service does the conversion from one currency to another. | ||
It is a C++ based service. | ||
|
||
## Building docker image | ||
|
||
To build the currency service, run the following from root directory | ||
of opentelemetry-demo-webstore | ||
|
||
```sh | ||
docker-compose build currencyservice | ||
``` | ||
|
||
## Run the service | ||
|
||
Execute the below command to run the service. | ||
|
||
```sh | ||
docker-compose up currencyservice | ||
``` | ||
|
||
## Run the client | ||
|
||
currencyclient is a sample client which sends some request to currency | ||
service. To run the client, execute the below command. | ||
|
||
```sh | ||
docker exec -it <container_name> currencyclient 7000 | ||
``` | ||
|
||
'7000' is port where currencyservice listens to. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.