Skip to content

Commit

Permalink
Merge pull request #22 from kurtosis-tech/lporoli/sns-sqs
Browse files Browse the repository at this point in the history
feat: adding the metrics service for the `sns` and `sqs` use case
  • Loading branch information
leoporoli authored Sep 25, 2024
2 parents 8d378be + 1d90485 commit d8a1996
Show file tree
Hide file tree
Showing 51 changed files with 794 additions and 98 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
uses: DeterminateSystems/flake-checker-action@main
with:
fail-mode: true
check-outdated: false

# Nix-specific logic begins here
- name: Nix Check
Expand Down Expand Up @@ -77,10 +78,10 @@ jobs:
nix build ./#containers.x86_64-linux.cartservice.arm64 --no-link --print-out-paths
nix build ./#containers.x86_64-linux.cartservice.amd64 --no-link --print-out-paths
- name: Build currencyexternalapi images
- name: Build metrics images
run: |
nix build ./#containers.x86_64-linux.currencyexternalapi.arm64 --no-link --print-out-paths
nix build ./#containers.x86_64-linux.currencyexternalapi.amd64 --no-link --print-out-paths
nix build ./#containers.x86_64-linux.metrics.arm64 --no-link --print-out-paths
nix build ./#containers.x86_64-linux.metrics.amd64 --no-link --print-out-paths
- name: Build frontend images
run: |
Expand All @@ -104,13 +105,13 @@ jobs:
# Set tag to be the branch name and version
nix develop --command tag-branch-version
nix run ./#publish-cartservice-container
nix run ./#publish-currencyexternalapi-container
nix run ./#publish-metrics-container
nix run ./#publish-frontend-container
nix run ./#publish-productcatalogservice-container
# Set tag to be the branch name
nix develop --command tag-branch
nix run ./#publish-cartservice-container
nix run ./#publish-currencyexternalapi-container
nix run ./#publish-metrics-container
nix run ./#publish-frontend-container
nix run ./#publish-productcatalogservice-container
22 changes: 16 additions & 6 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
FRONTEND_SERVICE_NAME='frontend'
CARTSERVICE_SERVICE_NAME='cartservice'
PRODUCTCATALOG_SERVICE_NAME='productcatalogservice'
METRICS_SERVICE_NAME='metrics'
DEV_IMAGE_SUFFIX='-dev-image'
FRONTEND_REF=FRONTEND_SERVICE_NAME + DEV_IMAGE_SUFFIX
CARTSERVICE_REF=CARTSERVICE_SERVICE_NAME + DEV_IMAGE_SUFFIX
PRODUCTCATALOG_REF=PRODUCTCATALOG_SERVICE_NAME + DEV_IMAGE_SUFFIX
METRICS_REF=METRICS_SERVICE_NAME + DEV_IMAGE_SUFFIX

# enforces a minimum Tilt version
version_settings(constraint='>=0.22.2')
Expand All @@ -26,7 +28,7 @@ if 'build' in arguments:
build_arg_len = len(build_arg)

# validate the 'build' argument
valid_build_arguments = [FRONTEND_SERVICE_NAME, CARTSERVICE_SERVICE_NAME, PRODUCTCATALOG_SERVICE_NAME]
valid_build_arguments = [FRONTEND_SERVICE_NAME, CARTSERVICE_SERVICE_NAME, PRODUCTCATALOG_SERVICE_NAME, METRICS_SERVICE_NAME]
for bu_arg in build_arg:
if bu_arg not in valid_build_arguments:
fail('build argument {} is not valid. Valid arguments are: {}'.format(bu_arg, valid_build_arguments))
Expand All @@ -40,7 +42,7 @@ if k8s_context() == 'minikube':
local('eval $(minikube docker-env)')

# set the env var to use the local Kontrol
local('export KARDINAL_CLI_DEV_MODE=TRUE')
os.environ["KARDINAL_CLI_DEV_MODE"] = "TRUE"

# clean current flows before creating new ones, it's just for the tilt up cmd
if config.tilt_subcommand == 'up':
Expand Down Expand Up @@ -70,16 +72,16 @@ if config.tilt_subcommand == 'up':
if 'cartservice' in build_arg:
docker_build(
CARTSERVICE_REF,
context='./src/cartservice',
dockerfile='./src/cartservice/Dockerfile',
context='./src',
dockerfile='./src/cartservice.dockerfile',
)

# PRODUCT CATALOG SERVICE
if 'productcatalogservice' in build_arg:
docker_build(
PRODUCTCATALOG_REF,
context='./src/productcatalogservice',
dockerfile='./src/productcatalogservice/Dockerfile',
context='./src',
dockerfile='./src/productcatalogservice.dockerfile',
)

# FRONTEND
Expand All @@ -90,6 +92,14 @@ if 'frontend' in build_arg:
dockerfile='./src/frontend.dockerfile',
)

# METRICS
if 'metrics' in build_arg:
docker_build(
METRICS_REF,
context='./src',
dockerfile='./src/metrics.dockerfile',
)

kardinal_topology_yaml = local(['kardinal', 'topology', 'print-manifest', '--add-trace-router'], quiet=True)
kardinal_topology_yaml_str = str(kardinal_topology_yaml)

Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

service_names = [
"cartservice"
"currencyexternalapi"
"frontend"
"metrics"
"productcatalogservice"
];
architectures = ["amd64" "arm64"];
Expand Down Expand Up @@ -166,7 +166,7 @@
inherit pkgs;
};

packages.currencyexternalapi = pkgs.callPackage ./src/currencyexternalapi {
packages.metrics = pkgs.callPackage ./src/metrics {
inherit pkgs;
};

Expand Down
89 changes: 85 additions & 4 deletions release/obd-kardinal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,22 @@ spec:
- name: "Cookie"
value: "shop_session-id=x-liveness-probe"
env:
- name: ADDRESS
value: ":8080"
- name: JSDELIVRAPIKEY
value: "prod"
- name: CARTSERVICEHOST
value: cartservice
- name: PRODUCTCATALOGSERVICEHOST
value: productcatalogservice
#- name: AWS_REGION
# value: us-east-1
#- name: AWS_ACCESS_KEY_ID
# value:
#- name: AWS_SECRET_ACCESS_KEY
# value:
#- name: QUEUE_URL
# value:
#- name: SNS_TOPIC_ARN
# value:
---
apiVersion: v1
kind: Service
Expand Down Expand Up @@ -170,7 +178,7 @@ metadata:
name: frontend-external
annotations:
kardinal.dev.service/ingress: "true"
kardinal.dev.service/host: "prod.app.localhost"
kardinal.dev.service/host: "baseline.app.localhost"
spec:
type: LoadBalancer
selector:
Expand Down Expand Up @@ -331,4 +339,77 @@ spec:
port: 8070
targetPort: 8070
protocol: TCP
appProtocol: HTTP
appProtocol: HTTP

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: metrics-v1
labels:
app: metrics
version: v1
spec:
selector:
matchLabels:
app: metrics
version: v1
template:
metadata:
labels:
app: metrics
version: v1
annotations:
sidecar.istio.io/rewriteAppHTTPProbers: "true"
spec:
containers:
- name: server
image: kurtosistech/metrics:main
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8091
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 8091
httpHeaders:
- name: "Cookie"
value: "shop_session-id=x-readiness-probe"
livenessProbe:
initialDelaySeconds: 10
httpGet:
path: "/_healthz"
port: 8091
httpHeaders:
- name: "Cookie"
value: "shop_session-id=x-liveness-probe"
#env:
#- name: AWS_REGION
# value: us-east-1
#- name: AWS_ACCESS_KEY_ID
# value:
#- name: AWS_SECRET_ACCESS_KEY
# value:
#- name: QUEUE_URL
# value:
#- name: SNS_TOPIC_ARN
# value:
---
apiVersion: v1
kind: Service
metadata:
name: metrics
labels:
app: metrics
version: v1
spec:
type: ClusterIP
selector:
app: metrics
ports:
- name: http
port: 8091
protocol: TCP
appProtocol: HTTP
targetPort: 8091
12 changes: 5 additions & 7 deletions src/cartservice/Dockerfile → src/cartservice.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ ENV CGO_ENABLED=0 GOOS=linux
WORKDIR /go/src/hipstershop

# Build Go binary
COPY Makefile go.mod go.sum ./
COPY ./cartservice ./cartservice
WORKDIR /go/src/hipstershop/cartservice
RUN go env -w GOPROXY=https://goproxy.io,direct/
RUN go mod download
COPY . .

# Skaffold passes in debug-oriented compiler flags
ARG SKAFFOLD_GO_GCFLAGS
RUN go build -gcflags="${SKAFFOLD_GO_GCFLAGS}" -o /go/src/hipstershop/cartservice .
RUN go build -o /go/src/hipstershop/cartservicebin .

# # Deployment container
FROM alpine:latest

# Install dependencies
RUN apk --update --no-cache add ca-certificates make protoc
RUN apk --update --no-cache add ca-certificates protoc

# These tools are for debuggin the containres
RUN apk add --no-cache \
Expand All @@ -35,6 +33,6 @@ RUN apk add --no-cache \
ENV GOTRACEBACK=single

COPY --from=builder /etc/ssl/certs /etc/ssl/certs
COPY --from=builder /go/src/hipstershop/cartservice /hipstershop/cartservice
COPY --from=builder /go/src/hipstershop/cartservicebin /hipstershop/cartservice

ENTRYPOINT ["/hipstershop/cartservice"]
1 change: 0 additions & 1 deletion src/cartservice/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.gitignore
Dockerfile
default.nix
gomod2nix.toml
2 changes: 1 addition & 1 deletion src/frontend.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ RUN apk --update --no-cache add ca-certificates make
# Build Go binary
COPY ./frontend ./frontend
COPY ./cartservice ./cartservice
COPY ./currencyexternalapi ./currencyexternalapi
COPY ./productcatalogservice ./productcatalogservice
COPY ./libraries ./libraries
WORKDIR /go/src/hipstershop/frontend

RUN go env -w GOPROXY=https://goproxy.io,direct/
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/currencyexternalservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package currencyexternalservice

import (
"context"
"github.com/kurtosis-tech/new-obd/src/currencyexternalapi"
"github.com/kurtosis-tech/new-obd/src/libraries/currencyexternalapi"
productcatalogservice_rest_types "github.com/kurtosis-tech/new-obd/src/productcatalogservice/api/http_rest/types"
)

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/currencyexternalservice/servicefactory.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package currencyexternalservice

import (
"github.com/kurtosis-tech/new-obd/src/currencyexternalapi"
"github.com/kurtosis-tech/new-obd/src/currencyexternalapi/config/jsdelivr"
"github.com/kurtosis-tech/new-obd/src/libraries/currencyexternalapi"
"github.com/kurtosis-tech/new-obd/src/libraries/currencyexternalapi/config/jsdelivr"
)

func CreateService(apiKey string) *CurrencyExternalService {
Expand Down
13 changes: 9 additions & 4 deletions src/frontend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@ toolchain go1.22.4

replace (
github.com/kurtosis-tech/new-obd/src/cartservice => ../cartservice
github.com/kurtosis-tech/new-obd/src/currencyexternalapi => ../currencyexternalapi
github.com/kurtosis-tech/new-obd/src/libraries/currencyexternalapi => ./../libraries/currencyexternalapi
github.com/kurtosis-tech/new-obd/src/libraries/events => ./../libraries/events
github.com/kurtosis-tech/new-obd/src/libraries/tracing => ./../libraries/tracing
github.com/kurtosis-tech/new-obd/src/productcatalogservice => ../productcatalogservice

)

require (
github.com/google/uuid v1.5.0
github.com/gorilla/mux v1.8.1
github.com/kurtosis-tech/new-obd/src/cartservice v0.0.0
github.com/kurtosis-tech/new-obd/src/currencyexternalapi v0.0.0
github.com/kurtosis-tech/new-obd/src/libraries/currencyexternalapi v0.0.0
github.com/kurtosis-tech/new-obd/src/libraries/events v0.0.0
github.com/kurtosis-tech/new-obd/src/libraries/tracing v0.0.0
github.com/kurtosis-tech/new-obd/src/productcatalogservice v0.0.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/sirupsen/logrus v1.9.3
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/golang/protobuf v1.5.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
golang.org/x/sys v0.20.0 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
Expand Down
16 changes: 12 additions & 4 deletions src/frontend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMz
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -54,6 +56,10 @@ github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
Expand All @@ -63,11 +69,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand Down Expand Up @@ -98,8 +103,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -141,6 +146,9 @@ google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
Loading

0 comments on commit d8a1996

Please sign in to comment.