Skip to content

Commit

Permalink
examples: update rideshare examples (#2990)
Browse files Browse the repository at this point in the history
  • Loading branch information
korniltsev authored Feb 9, 2024
1 parent a05c3f3 commit 9baa913
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 34 deletions.
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -414,19 +414,7 @@ tools/monitoring/environments/default/spec.json: $(BIN)/tk $(BIN)/kind
echo "import 'monitoring.libsonnet'" > tools/monitoring/environments/default/main.jsonnet
$(BIN)/tk env set tools/monitoring/environments/default --server=$(shell $(BIN)/kind get kubeconfig --name pyroscope-dev | grep server: | sed 's/server://g' | xargs) --namespace=monitoring

.PHONY: tools/update_examples
tools/update_examples:
go run tools/update_examples.go

.phony: rideshare/docker/push
rideshare/docker/push:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-golang -t $(IMAGE_PREFIX)pyroscope-rideshare-golang:$(IMAGE_TAG) examples/golang-push/rideshare
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-loadgen -t $(IMAGE_PREFIX)pyroscope-rideshare-loadgen:$(IMAGE_TAG) -f examples/golang-push/rideshare/Dockerfile.load-generator examples/golang-push/rideshare
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-python -t $(IMAGE_PREFIX)pyroscope-rideshare-python:$(IMAGE_TAG) examples/python/rideshare/flask
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-ruby -t $(IMAGE_PREFIX)pyroscope-rideshare-ruby:$(IMAGE_TAG) examples/ruby/rideshare_rails
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-dotnet -t $(IMAGE_PREFIX)pyroscope-rideshare-dotnet:$(IMAGE_TAG) examples/dotnet/rideshare/
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-java -t $(IMAGE_PREFIX)pyroscope-rideshare-java:$(IMAGE_TAG) examples/java/rideshare
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-rust -t $(IMAGE_PREFIX)pyroscope-rideshare-rust:$(IMAGE_TAG) examples/rust/rideshare
include Makefile.examples

.PHONY: docs/%
docs/%:
Expand Down
35 changes: 35 additions & 0 deletions Makefile.examples
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

.PHONY: tools/update_examples
tools/update_examples:
go run tools/update_examples.go

.PHONY: rideshare/docker/push
rideshare/docker/push: rideshare/docker/push-golang rideshare/docker/push-loadgen rideshare/docker/push-python rideshare/docker/push-ruby rideshare/docker/push-dotnet rideshare/docker/push-java rideshare/docker/push-rust

.PHONY: rideshare/docker/push-golang
rideshare/docker/push-golang:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-golang -t $(IMAGE_PREFIX)pyroscope-rideshare-golang:$(IMAGE_TAG) examples/golang-push/rideshare

.PHONY: rideshare/docker/push-loadgen
rideshare/docker/push-loadgen:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-loadgen -t $(IMAGE_PREFIX)pyroscope-rideshare-loadgen:$(IMAGE_TAG) -f examples/golang-push/rideshare/Dockerfile.load-generator examples/golang-push/rideshare

.PHONY: rideshare/docker/push-python
rideshare/docker/push-python:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-python -t $(IMAGE_PREFIX)pyroscope-rideshare-python:$(IMAGE_TAG) examples/python/rideshare/flask

.PHONY: rideshare/docker/push-ruby
rideshare/docker/push-ruby:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-ruby -t $(IMAGE_PREFIX)pyroscope-rideshare-ruby:$(IMAGE_TAG) examples/ruby/rideshare_rails

.PHONY: rideshare/docker/push-dotnet
rideshare/docker/push-dotnet:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-dotnet -t $(IMAGE_PREFIX)pyroscope-rideshare-dotnet:$(IMAGE_TAG) examples/dotnet/rideshare/

.PHONY: rideshare/docker/push-java
rideshare/docker/push-java:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-java -t $(IMAGE_PREFIX)pyroscope-rideshare-java:$(IMAGE_TAG) examples/java/rideshare

.PHONY: rideshare/docker/push-rust
rideshare/docker/push-rust:
docker buildx build --push --platform $(IMAGE_PLATFORM) -t $(IMAGE_PREFIX)pyroscope-rideshare-rust -t $(IMAGE_PREFIX)pyroscope-rideshare-rust:$(IMAGE_TAG) examples/rust/rideshare
4 changes: 2 additions & 2 deletions examples/dotnet/rideshare/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ENV PYROSCOPE_PROFILING_ENABLED=1
ENV PYROSCOPE_PROFILING_ALLOCATION_ENABLED=true
ENV PYROSCOPE_PROFILING_CONTENTION_ENABLED=true
ENV PYROSCOPE_PROFILING_EXCEPTION_ENABLED=true
ENV ASPNETCORE_URLS=http://*:5000
ENV RIDESHARE_LISTEN_PORT=5000


CMD ["dotnet", "/dotnet/example.dll"]
CMD sh -c "ASPNETCORE_URLS=http://*:${RIDESHARE_LISTEN_PORT} exec dotnet /dotnet/example.dll"
8 changes: 4 additions & 4 deletions examples/dotnet/rideshare/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- REGION=us-east
- PYROSCOPE_LABELS=region:us-east
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
- ASPNETCORE_URLS=http://*:5000
- RIDESHARE_LISTEN_PORT=5000
build:
context: .

Expand All @@ -25,7 +25,7 @@ services:
- REGION=eu-north
- PYROSCOPE_LABELS=region:eu-north
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
- ASPNETCORE_URLS=http://*:5000
- RIDESHARE_LISTEN_PORT=5000

build:
context: .
Expand All @@ -38,7 +38,7 @@ services:
- REGION=ap-south
- PYROSCOPE_LABELS=region:ap-south
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
- ASPNETCORE_URLS=http://*:5000
- RIDESHARE_LISTEN_PORT=5000
build:
context: .

Expand All @@ -50,7 +50,7 @@ services:
- REGION=ap-south
- PYROSCOPE_LABELS=region:ap-south-alpine
- PYROSCOPE_SERVER_ADDRESS=http://pyroscope:4040
- ASPNETCORE_URLS=http://*:5000
- RIDESHARE_LISTEN_PORT=5000
build:
context: .
dockerfile: musl.Dockerfile
Expand Down
20 changes: 10 additions & 10 deletions examples/golang-push/rideshare/loadgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"rideshare/rideshare"
)

var hosts = []string{}
var urls = []string{}

var vehicles = []string{
"bike",
Expand All @@ -32,12 +32,12 @@ var client *http.Client
func main() {
c := rideshare.ReadConfig()
c.AppName = "load-generator"
hosts = os.Args[1:]
if len(hosts) == 0 {
hosts = []string{
"us-east",
"eu-north",
"ap-south",
urls = os.Args[1:]
if len(urls) == 0 {
urls = []string{
"http://us-east:5000",
"http://eu-north:5000",
"http://ap-south:5000",
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ func main() {
_ = tp.Shutdown(context.Background())
}()

groups := groupHosts(hosts, groupByFactor)
groups := groupHosts(urls, groupByFactor)
for _, group := range groups {
go func(group []string) {
for {
Expand Down Expand Up @@ -110,7 +110,7 @@ func groupHosts(hosts []string, groupsOf int) [][]string {
return res
}

func orderVehicle(ctx context.Context, host, vehicle string) error {
func orderVehicle(ctx context.Context, baseURL, vehicle string) error {
ctx, span := otel.GetTracerProvider().Tracer("").Start(ctx, "OrderVehicle")
defer span.End()

Expand All @@ -124,7 +124,7 @@ func orderVehicle(ctx context.Context, host, vehicle string) error {
}

span.SetAttributes(attribute.String("vehicle", vehicle))
url := fmt.Sprintf("http://%s:5000/%s", host, vehicle)
url := fmt.Sprintf("%s/%s", baseURL, vehicle)
fmt.Println("requesting", url)

req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
Expand Down
4 changes: 3 additions & 1 deletion examples/golang-push/rideshare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -72,7 +73,8 @@ func main() {
http.Handle("/scooter", otelhttp.NewHandler(http.HandlerFunc(scooterRoute), "ScooterHandler"))
http.Handle("/car", otelhttp.NewHandler(http.HandlerFunc(carRoute), "CarHandler"))

log.Fatal(http.ListenAndServe(":5000", nil))
addr := fmt.Sprintf(":%s", config.RideshareListenPort)
log.Fatal(http.ListenAndServe(addr, nil))
}

func setupOTEL(c rideshare.Config) (tp *sdktrace.TracerProvider, err error) {
Expand Down
6 changes: 6 additions & 0 deletions examples/golang-push/rideshare/rideshare/rideshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Config struct {

ParametersPoolSize int
ParametersPoolBufferSize int
RideshareListenPort string
}

func ReadConfig() Config {
Expand Down Expand Up @@ -109,6 +110,11 @@ func ReadConfig() Config {
// more readable from as an env var, we represent the env var value in
// kb.
ParametersPoolBufferSize: envIntOrDefault("PARAMETERS_POOL_BUFFER_SIZE_KB", 1000) * 1000,

RideshareListenPort: os.Getenv("RIDESHARE_LISTEN_PORT"),
}
if c.RideshareListenPort == "" {
c.RideshareListenPort = "5000"
}
if c.AppName == "" {
c.AppName = "ride-sharing-app"
Expand Down
3 changes: 2 additions & 1 deletion examples/java/rideshare/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ENV PYROSCOPE_PROFILER_ALLOC=512k
ENV PYROSCOPE_UPLOAD_INTERVAL=15s
ENV PYROSCOPE_LOG_LEVEL=debug
ENV PYROSCOPE_SERVER_ADDRESS=http://localhost:4040
ENV RIDESHARE_LISTEN_PORT=5000
EXPOSE 5000

COPY --from=builder /opt/app/build/libs/rideshare-1.0-SNAPSHOT.jar /opt/app/build/libs/rideshare-1.0-SNAPSHOT.jar
Expand All @@ -38,4 +39,4 @@ WORKDIR /opt/app

ADD https://github.com/grafana/pyroscope-java/releases/download/v0.12.2/pyroscope.jar /opt/app/pyroscope.jar

CMD ["java", "-Dserver.port=5000", "-javaagent:pyroscope.jar", "-jar", "./build/libs/rideshare-1.0-SNAPSHOT.jar" ]
CMD sh -c "exec java -Dserver.port=${RIDESHARE_LISTEN_PORT} -javaagent:pyroscope.jar -jar ./build/libs/rideshare-1.0-SNAPSHOT.jar"
3 changes: 2 additions & 1 deletion examples/python/rideshare/flask/lib/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
server_addr = os.getenv("PYROSCOPE_SERVER_ADDRESS", "http://pyroscope:4040")
basic_auth_username = os.getenv("PYROSCOPE_BASIC_AUTH_USER", "")
basic_auth_password = os.getenv("PYROSCOPE_BASIC_AUTH_PASSWORD", "")
port = int(os.getenv("RIDESHARE_LISTEN_PORT", "5000"))

pyroscope.configure(
application_name = app_name,
Expand Down Expand Up @@ -49,5 +50,5 @@ def environment():
return result

if __name__ == '__main__':
app.run(threaded=False, processes=1, host='0.0.0.0', debug=False)
app.run(threaded=False, processes=1, host='0.0.0.0', port=port, debug=False)

2 changes: 1 addition & 1 deletion examples/ruby/rideshare/lib/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@


set :bind, '0.0.0.0'
set :port, 5000
set :port, ENV["RIDESHARE_LISTEN_PORT"] || 5000

run Sinatra::Application.run!
4 changes: 3 additions & 1 deletion examples/ruby/rideshare_rails/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ EXPOSE 5000

RUN rm -f tmp/pids/server.pid

CMD ["rails", "s", "-b", "0.0.0.0", "-p", "5000"]
ENV RIDESHARE_LISTEN_PORT=5000

CMD sh -c "exec rails s -b 0.0.0.0 -p ${RIDESHARE_LISTEN_PORT}"

0 comments on commit 9baa913

Please sign in to comment.