From 67750603bc33c99638b22b659ef04636ac976b12 Mon Sep 17 00:00:00 2001 From: Lam Tran Date: Tue, 12 Mar 2024 23:52:23 +0700 Subject: [PATCH 1/4] refactor(accountingservice): refactor accountingservice dockerfile (#1439) Co-authored-by: Austin Parker --- src/accountingservice/Dockerfile | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/accountingservice/Dockerfile b/src/accountingservice/Dockerfile index 1321675d70..8a1ab6556b 100644 --- a/src/accountingservice/Dockerfile +++ b/src/accountingservice/Dockerfile @@ -2,20 +2,26 @@ # SPDX-License-Identifier: Apache-2.0 -FROM golang:1.22.0-alpine AS builder -RUN apk update && apk add --no-cache make protobuf-dev -RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest -RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest - -WORKDIR /usr/src/app/ - -COPY ./src/accountingservice/ ./ -COPY ./pb/ ./pb - -RUN protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ -RUN go build -o /go/bin/accountingservice/ - -# ----------------------------------------------------------------------------- +FROM golang:1.22-alpine AS builder + +WORKDIR /usr/src/app + +RUN apk update \ + && apk add --no-cache make protobuf-dev + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=./src/accountingservice/go.sum,target=go.sum \ + --mount=type=bind,source=./src/accountingservice/go.mod,target=go.mod \ + --mount=type=bind,source=./src/accountingservice/tools.go,target=tools.go \ + go mod download \ + && go list -e -f '{{range .Imports}}{{.}} {{end}}' tools.go | CGO_ENABLED=0 xargs go install -mod=readonly + +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=bind,rw,source=./src/accountingservice,target=. \ + --mount=type=bind,rw,source=./pb,target=./pb \ + protoc -I ./pb ./pb/demo.proto --go_out=./ --go-grpc_out=./ \ + && go build -ldflags "-s -w" -o /go/bin/accountingservice/ ./ FROM alpine From 87e051db675175d5f3746059769ad03940884efb Mon Sep 17 00:00:00 2001 From: "Pal K. Klucsik" Date: Wed, 13 Mar 2024 12:21:02 +0100 Subject: [PATCH 2/4] [Frontend-proxy] Add restart policy to compose files (#1448) * [Frontend-proxy] Add restart policy to compose files * Update CHANGELOG.md --------- Co-authored-by: Juliano Costa --- CHANGELOG.md | 2 ++ docker-compose.minimal.yml | 1 + docker-compose.yml | 1 + 3 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb0c491442..03d82cc02c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ the release. ([#1427](https://github.com/open-telemetry/opentelemetry-demo/pull/1427)) * [chore] - Update Telemetry Components ([#1440](https://github.com/open-telemetry/opentelemetry-demo/pull/1440)) +* [Frontend-proxy] Add restart policy to compose file + ([#1448](https://github.com/open-telemetry/opentelemetry-demo/pull/1448)) ## 1.8.0 diff --git a/docker-compose.minimal.yml b/docker-compose.minimal.yml index e34926f726..b467a80292 100644 --- a/docker-compose.minimal.yml +++ b/docker-compose.minimal.yml @@ -238,6 +238,7 @@ services: resources: limits: memory: 50M + restart: unless-stopped ports: - "${ENVOY_PORT}:${ENVOY_PORT}" - 10000:10000 diff --git a/docker-compose.yml b/docker-compose.yml index 55ec39ecab..00f0a27061 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -312,6 +312,7 @@ services: resources: limits: memory: 50M + restart: unless-stopped ports: - "${ENVOY_PORT}:${ENVOY_PORT}" - 10000:10000 From 5a5eb25549f90b30f3b63452f817a08d0f466896 Mon Sep 17 00:00:00 2001 From: Austin Parker Date: Wed, 13 Mar 2024 08:01:36 -0400 Subject: [PATCH 3/4] Reset quantity in frontend when product changes (#1447) * reset quantity when product ID changes * update changelog --------- Co-authored-by: Juliano Costa --- CHANGELOG.md | 2 ++ src/frontend/pages/product/[productId]/index.tsx | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03d82cc02c..f66a41042a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ the release. ## Unreleased +* [frontend] reset quantity when new product selected + ([#1447](https://github.com/open-telemetry/opentelemetry-demo/pull/1447)) * [featureflag] deprecate in favor of flagd ([#1338](https://github.com/open-telemetry/opentelemetry-demo/pull/1388)) * [checkoutservice] add producer interceptor for tracing diff --git a/src/frontend/pages/product/[productId]/index.tsx b/src/frontend/pages/product/[productId]/index.tsx index 02a9cfaca3..c0a4dbd086 100644 --- a/src/frontend/pages/product/[productId]/index.tsx +++ b/src/frontend/pages/product/[productId]/index.tsx @@ -4,7 +4,7 @@ import { NextPage } from 'next'; import Image from 'next/image'; import { useRouter } from 'next/router'; -import { useCallback, useState } from 'react'; +import { useCallback, useState, useEffect } from 'react'; import { useQuery } from '@tanstack/react-query'; import Ad from '../../../components/Ad'; import Footer from '../../../components/Footer'; @@ -32,6 +32,10 @@ const ProductDetail: NextPage = () => { const { selectedCurrency } = useCurrency(); const productId = query.productId as string; + useEffect(() => { + setQuantity(1); + }, [productId]); + const { data: { name, From def3a4c64ee10dc8e9d56c87e9725972beddd43f Mon Sep 17 00:00:00 2001 From: Austin Parker Date: Wed, 13 Mar 2024 11:30:14 -0400 Subject: [PATCH 4/4] Emit load generator logs via OTLP (#1446) * add otel logging to loadgen * attach to root logger * actually output logs * update changelog * fix sanity --------- Co-authored-by: Juliano Costa --- CHANGELOG.md | 2 ++ src/loadgenerator/Dockerfile | 2 +- src/loadgenerator/locustfile.py | 27 ++++++++++++++++++++++++++- src/loadgenerator/requirements.txt | 23 ++++++++++++----------- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f66a41042a..135a3407df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ the release. ## Unreleased +* [loadgenerator] emit logs via OTLP + ([#1446](https://github.com/open-telemetry/opentelemetry-demo/pull/1446)) * [frontend] reset quantity when new product selected ([#1447](https://github.com/open-telemetry/opentelemetry-demo/pull/1447)) * [featureflag] deprecate in favor of flagd diff --git a/src/loadgenerator/Dockerfile b/src/loadgenerator/Dockerfile index ae5d4d879a..5c8427f597 100644 --- a/src/loadgenerator/Dockerfile +++ b/src/loadgenerator/Dockerfile @@ -20,4 +20,4 @@ COPY ./src/loadgenerator/people.json . ENV LOCUST_PLAYWRIGHT=1 ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers RUN playwright install --with-deps chromium -ENTRYPOINT locust +ENTRYPOINT locust --skip-log-setup diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 9f87112195..9375df2d00 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -8,6 +8,9 @@ import os import random import uuid +import logging +import sys +from pythonjsonlogger import jsonlogger from locust import HttpUser, task, between from locust_plugins.users.playwright import PlaywrightUser, pw, PageWithRetry, event @@ -23,8 +26,30 @@ from opentelemetry.instrumentation.requests import RequestsInstrumentor from opentelemetry.instrumentation.system_metrics import SystemMetricsInstrumentor from opentelemetry.instrumentation.urllib3 import URLLib3Instrumentor +from opentelemetry._logs import set_logger_provider +from opentelemetry.exporter.otlp.proto.grpc._log_exporter import ( + OTLPLogExporter, +) +from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler +from opentelemetry.sdk._logs.export import BatchLogRecordProcessor +from opentelemetry.sdk.resources import Resource from playwright.async_api import Route, Request +logger_provider = LoggerProvider(resource=Resource.create( + { + "service.name": "loadgenerator", + } + ),) +set_logger_provider(logger_provider) + +exporter = OTLPLogExporter(insecure=True) +logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter)) +handler = LoggingHandler(level=logging.INFO, logger_provider=logger_provider) + +# Attach OTLP handler to locust logger +logging.getLogger().addHandler(handler) +logging.getLogger().setLevel(logging.INFO) + exporter = OTLPMetricExporter(insecure=True) set_meter_provider(MeterProvider([PeriodicExportingMetricReader(exporter)])) @@ -37,6 +62,7 @@ RequestsInstrumentor().instrument() SystemMetricsInstrumentor().instrument() URLLib3Instrumentor().instrument() +logging.info("Instrumentation complete") categories = [ "binoculars", @@ -64,7 +90,6 @@ people_file = open('people.json') people = json.load(people_file) - class WebsiteUser(HttpUser): wait_time = between(1, 10) diff --git a/src/loadgenerator/requirements.txt b/src/loadgenerator/requirements.txt index 2b685cbc07..88aba3fdc3 100644 --- a/src/loadgenerator/requirements.txt +++ b/src/loadgenerator/requirements.txt @@ -19,17 +19,17 @@ locust==2.18.2 locust_plugins==3.4.0 markupsafe==2.1.3 msgpack==1.0.7 -opentelemetry-api==1.22.0 -opentelemetry-exporter-otlp-proto-grpc==1.22.0 -opentelemetry-instrumentation==0.43b0 -opentelemetry-instrumentation-jinja2==0.43b0 -opentelemetry-instrumentation-requests==0.43b0 -opentelemetry-instrumentation-system-metrics==0.43b0 -opentelemetry-instrumentation-urllib3==0.43b0 -opentelemetry-proto==1.22.0 -opentelemetry-sdk==1.22.0 -opentelemetry-semantic-conventions==0.43b0 -opentelemetry-util-http==0.43b0 +opentelemetry-api==1.23.0 +opentelemetry-exporter-otlp-proto-grpc==1.23.0 +opentelemetry-instrumentation==0.44b0 +opentelemetry-instrumentation-jinja2==0.44b0 +opentelemetry-instrumentation-requests==0.44b0 +opentelemetry-instrumentation-system-metrics==0.44b0 +opentelemetry-instrumentation-urllib3==0.44b0 +opentelemetry-proto==1.23.0 +opentelemetry-sdk==1.23.0 +opentelemetry-semantic-conventions==0.44b0 +opentelemetry-util-http==0.44b0 protobuf==4.25.0 psutil==5.9.6 pyzmq==25.1.1 @@ -42,3 +42,4 @@ werkzeug==3.0.1 wrapt==1.16.0 zope-event==5.0 zope-interface==6.1 +python-json-logger==2.0.7