Skip to content

Commit

Permalink
adding grafana datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
jurabek committed Feb 10, 2024
1 parent ef832fb commit b108a97
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 22 deletions.
5 changes: 5 additions & 0 deletions k8s-kustomize/infrastructure/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kustomize build ./crds | kubectl apply -f -

# wait all CRD's are available
kustomize build ./crds | kubectl wait --for condition=established --timeout=60s -f -
kustomize build . | kubectl apply -f -
49 changes: 49 additions & 0 deletions k8s-kustomize/infrastructure/monitoring/grafana-datasources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: 1

datasources:
- name: Prometheus
type: prometheus
uid: prometheus
access: proxy
orgId: 1
url: http://prometheus:9090
basicAuth: false
isDefault: false
version: 1
editable: false
jsonData:
httpMethod: GET

- name: Loki
type: loki
access: proxy
url: http://loki:3100
basicAuth: false
isDefault: true
version: 1
editable: false
jsonData:
httpHeaderName1: "X-Scope-OrgID"
derivedFields:
- datasourceName: Tempo
matcherRegex: (?:traceID|trace_id):(\\w+)
name: TraceID
url: "$${__value.raw}"
datasourceUid: tempo
secureJsonData:
httpHeaderValue1: "tenant1"

- name: Tempo
type: tempo
access: proxy
orgId: 1
url: http://tempo-tempostack-query-frontend:3200
basicAuth: false
version: 1
editable: false
apiVersion: 1
uid: tempo
jsonData:
httpMethod: GET
serviceMap:
datasourceUid: prometheus
9 changes: 9 additions & 0 deletions k8s-kustomize/infrastructure/monitoring/grafana.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,22 @@ spec:
requests:
cpu: 250m
memory: 750Mi
limits:
cpu: 250m
memory: 750Mi
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-pv
- mountPath: /etc/grafana/provisioning/datasources
name: grafana-datasources

volumes:
- name: grafana-pv
persistentVolumeClaim:
claimName: grafana-pvc
- name: grafana-datasources
configMap:
name: grafana-datasource-config
---
apiVersion: v1
kind: Service
Expand Down
50 changes: 50 additions & 0 deletions k8s-kustomize/infrastructure/monitoring/jaeger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: jaeger-all-in-one
spec:
replicas: 1
selector:
matchLabels:
app: jaeger
template:
metadata:
labels:
app: jaeger
spec:
containers:
- name: jaeger
image: jaegertracing/all-in-one:latest
ports:
- containerPort: 16686
- containerPort: 14268
- containerPort: 14250
- containerPort: 4317
- containerPort: 4318

---
apiVersion: v1
kind: Service
metadata:
name: jaeger-service
spec:
type: NodePort
selector:
app: jaeger
ports:
- name: ui
port: 16686
targetPort: 16686
nodePort: 30001
- name: collector
port: 14268
targetPort: 14268
- name: grpc
port: 14250
targetPort: 14250
- name: otlp-grpc
port: 4317
targetPort: 4317
- name: otlp-http
port: 4318
targetPort: 4318
9 changes: 8 additions & 1 deletion k8s-kustomize/infrastructure/monitoring/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ namespace: monitoring
generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- files:
- datasource.yaml=grafana-datasources.yaml
name: grafana-datasource-config

resources:
- "namespace.yaml"
- "tempo.yaml"
- "otel-collector.yaml"
- "grafana.yaml"
- "grafana.yaml"
- "jaeger.yaml"
- "zipkin.yaml"
19 changes: 13 additions & 6 deletions k8s-kustomize/infrastructure/monitoring/otel-collector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ spec:
mode: daemonset
config: |
receivers:
opencensus:
endpoint: 0.0.0.0:55678
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
http:
endpoint: 0.0.0.0:4318
exporters:
otlp:
Expand All @@ -20,12 +24,15 @@ spec:
logging:
loglevel: debug
otlp/jaeger:
endpoint: jaeger-service.monitoring.svc.cluster.local:4317
tls:
insecure: true
otlphttp:
endpoint: "https://collector.gethelios.dev"
traces_endpoint: "https://collector.gethelios.dev/v1/traces"
headers:
Authorization: ${env:HS_API_TOKEN}
zipkin:
endpoint: http://zipkin-service.monitoring.svc.cluster.local:9411/api/v2/spans
tls:
insecure: true
processors:
batch:
Expand All @@ -52,7 +59,7 @@ spec:
traces:
receivers: [otlp]
processors: [batch]
exporters: [otlp, otlphttp]
exporters: [otlp, otlp/jaeger, zipkin]
metrics:
receivers: [otlp]
Expand Down
33 changes: 33 additions & 0 deletions k8s-kustomize/infrastructure/monitoring/zipkin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: zipkin-all-in-one
spec:
replicas: 1
selector:
matchLabels:
app: zipkin
template:
metadata:
labels:
app: zipkin
spec:
containers:
- name: zipkin
image: openzipkin/zipkin:latest
ports:
- containerPort: 9411

---
apiVersion: v1
kind: Service
metadata:
name: zipkin-service
spec:
type: NodePort
selector:
app: zipkin
ports:
- port: 9411
targetPort: 9411
nodePort: 30002
30 changes: 30 additions & 0 deletions src/backend/docker/docker-compose.logto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This compose file is for demonstration only, do not use in prod.
version: "3.9"
services:
app:
depends_on:
postgres:
condition: service_healthy
image: svhd/logto:${TAG-latest}
entrypoint: ["sh", "-c", "npm run cli db seed -- --swe && npm start"]
ports:
- 3001:3001
- 3002:3002
environment:
- TRUST_PROXY_HEADER=1
- DB_URL=postgres://postgres:p0stgr3s@postgres:5432/logto
# Mandatory for GitPod to map host env to the container, thus GitPod can dynamically configure the public URL of Logto;
# Or, you can leverage it for local testing.
- ENDPOINT
- ADMIN_ENDPOINT
postgres:
image: postgres:14-alpine
user: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: p0stgr3s
healthcheck:
test: ["CMD-SHELL", "pg_isready"]
interval: 10s
timeout: 5s
retries: 5
83 changes: 68 additions & 15 deletions src/backend/load-tests/checkout.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import http from "k6/http";
import { sleep } from "k6";
import { check, sleep } from "k6";
import faker from "k6/x/faker";

export const options = {
vus: 300,
Expand All @@ -9,32 +10,84 @@ export const options = {
},
};

const baseUrl = "http://localhost:8080";
const catalogItems = baseUrl + "/cart/api/v1/items/all";
const baseUrl = "http://localhost";
const cartUrl = baseUrl + "/shoppingcart";
const catalogUrl = baseUrl + "/catalog";
const checkoutUrl = baseUrl + "/checkout";

export default function () {
const customer_id = "dfdee7b6-04d3-4d77-89a9-6542a4f2f31a";
const foods = http.get(baseUrl + "/catalog/items/all").json();
const getFoods = http.get(catalogUrl + "/items/all");
check(getFoods, {
"get catalog items status was 200": (r) => r.status == 200,
});

if (getFoods.status != 200) {
console.log(getFoods.status);
}
return;

const foods = getFoods.json();
const food = foods[Math.floor(Math.random() * foods.length)];

http.post(
catalogItems,
const user_id = faker.uuid();
// create new cart
const createCart = http.post(
cartUrl + "/api/v1/cart",
JSON.stringify({
customer_id,
items: [
{
food_id: food.id,
food_name: food.name,
old_unit_price: 0,
picture: food.image,
quantity: Math.floor(Math.random() * 20),
img: food.image,
item_id: food.id,
product_description: food.description,
product_name: food.name,
quantity: faker.number(1, 40),
unit_price: food.price,
},
],
user_id,
})
);

sleep(1);
check(createCart, {
"create new cart was 200": (r) => r.status == 200,
});

// checkout
const newCart = createCart.json();
const creditCard = faker.creditCard();
const cardExp = creditCard.exp.split("/");

const address = faker.address();

http.post(baseUrl + "");
const checkoutBody = JSON.stringify({
address: {
city: address.city,
country: address.country,
state: address.state,
street_address: address.address,
zip_code: Number(address.zip),
},
credit_card: {
name_on_card: faker.name(),
credit_card_cvv: Number(creditCard.cvv),
credit_card_expiration_month: Number(cardExp[0]),
credit_card_expiration_year: Number(cardExp[1]),
credit_card_number: creditCard.number,
},
user_id,
email: faker.email(),
user_currency: faker.currency().short,
cart_id: newCart.id,
});

const checkout = http.post(checkoutUrl + "/api/v1/checkout", checkoutBody, {
headers: { "Content-Type": "application/json" },
});
check(checkout, {
"checkout was 200": (r) => r.status == 200,
});

console.log(checkout.json());

sleep(1);
}

0 comments on commit b108a97

Please sign in to comment.