Skip to content

Commit

Permalink
feat: add metrics otel/prometheus - expose multiaddr
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Ramon Mañes <jose@celestia.org>
  • Loading branch information
tty47 committed Jul 26, 2023
1 parent 480b5f2 commit 96ac7cc
Show file tree
Hide file tree
Showing 17 changed files with 499 additions and 352 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
torch

.DS_Store
.idea

*otel-agent-celestia.yaml
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /go/bin/torch ./cmd/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /go/bin/torch ./cmd/main.go

FROM alpine:latest
WORKDIR /
Expand Down
11 changes: 11 additions & 0 deletions Dockerfile_local
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.20.3-bullseye AS builder
WORKDIR /
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
COPY torch /go/bin/torch

FROM alpine:latest
WORKDIR /
COPY --from=builder /go/bin/torch .
ENTRYPOINT ["./torch"]
35 changes: 31 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
PROJECT_NAME=torch
REPOSITORY_NAME=torch
PROJECT_NAME := $(shell basename `pwd`)
REPOSITORY_NAME := $(shell basename `pwd`)
REGISTRY_NAME=ghcr.io/jrmanes
LOCAL_DEV=local

# Go
.PHYONY: run build test test_cover get docs
.PHYONY: run build test test_cover get docs clean_bin
run:
go run ./cmd/main.go

Expand All @@ -25,21 +27,46 @@ get:
docs:
godoc -http=:6060

clean_bin:
rm ./${PROJECT_NAME} || true

# Docker
docker_build:
docker build -f Dockerfile -t ${PROJECT_NAME} -t ${PROJECT_NAME}:latest .
.PHYONY: docker_build

docker_build_local_push:
#GOOS=linux go build -o ./torch ./cmd/main.go
docker build -f Dockerfile -t ${PROJECT_NAME} .
docker tag ${PROJECT_NAME}:latest localhost:5000/${REPOSITORY_NAME}:latest
docker push localhost:5000/${REPOSITORY_NAME}:latest
.PHYONY: docker_build_local_push

docker_build_local_push_gh: clean_bin
GOOS=linux GOARCH=amd64 go build -o ./${PROJECT_NAME} ./cmd/main.go &&\
docker build -f Dockerfile_local -t ${REGISTRY_NAME}/${PROJECT_NAME}:latest .
docker push ${REGISTRY_NAME}/${PROJECT_NAME}:latest
.PHYONY: docker_build_local_push_gh

docker_run:
docker run -p 8080:8080 ${PROJECT_NAME}:latest
.PHYONY: docker_run

kubectl_apply:
kubectl delete -f ./deployment/deployment.yaml ;\
kubectl apply -f ./deployment/deployment.yaml
.PHYONY: kubectl_apply

kubectl_kustomize:
kubectl delete -k ./deployment/overlays/${LOCAL_DEV} ;\
kubectl apply -k ./deployment/overlays/${LOCAL_DEV}
.PHYONY: kubectl_kustomize

kubectl_kustomize_delete:
kubectl delete -k ./deployment/overlays/${LOCAL_DEV}
.PHYONY: kubectl_kustomize_delete

kubectl_deploy: docker_build_local_push kubectl_apply
.PHYONY: kubectl_deploy

kubectl_remote_kustomize_deploy: docker_build_local_push_gh kubectl_kustomize
.PHYONY: kubectl_remote_kustomize_deploy
17 changes: 15 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"io/ioutil"

"github.com/jrmanes/torch/config"
Expand Down Expand Up @@ -30,20 +31,32 @@ func ParseFlags() config.MutualPeersConfig {
file, err := ioutil.ReadFile(*configFile)
if err != nil {
log.Error("Config file doesn't exist...", err)
panic(err)
}

// Unmarshal the YAML into a struct
err = yaml.Unmarshal(file, &cfg)
if err != nil {
log.Error("Cannot unmarshal the config file...", err)
panic(err)
}

return cfg
}

func PrintName() {
torch := `
================================
__________ ____ ________ __
/_ __/ __ \/ __ \/ ____/ / / /
/ / / / / / /_/ / / / /_/ /
/ / / /_/ / _, _/ /___/ __ /
/_/ \____/_/ |_|\____/_/ /_/
================================
`
fmt.Println(torch)
}

func main() {
PrintName()
// Parse the command-line flags and read the configuration file
log.Info("Running on namespace: ", k8s.GetCurrentNamespace())
cfg = ParseFlags()
Expand Down
33 changes: 29 additions & 4 deletions deployment/base/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ spec:
args:
- ./torch --config-file /config/config.yaml
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: HTTP_PORT
value: "8080"
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- containerPort: 8080
volumeMounts:
Expand All @@ -42,10 +44,33 @@ spec:
limits:
memory: "100Mi"
cpu: "100m"
- name: otel-agent
image: otel/opentelemetry-collector-contrib:SET-IT
command:
- '/otelcol-contrib'
- '--config=/conf/otel-agent.yaml'
volumeMounts:
- name: otel-agent
mountPath: "/conf/otel-agent.yaml"
subPath: otel-agent-celestia.yaml
ports:
- name: prometheus-otel
containerPort: 8888
- name: prometheus
containerPort: 9090
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
memory: 200Mi
volumes:
- name: config
configMap:
name: config
items:
- key: config.yaml
path: config.yaml
- name: otel-agent
configMap:
name: otel-agent
39 changes: 39 additions & 0 deletions deployment/overlays/local/config/otel-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#extensions:
# basicauth/otlp:
# client_auth:
# username: <uid>
# # TODO: use a secret manager!
# password: "XYZ"

receivers:
otlp:
protocols:
http:
endpoint: "localhost:4318"
prometheus:
config:
scrape_configs:
- job_name: 'torch'
scrape_interval: 1m
static_configs:
- targets: ['localhost:8080']

exporters:
otlphttp:
# auth:
# authenticator: basicauth/otlp
endpoint: https://otlp-gateway-prod-us-central-0.grafana.net/otlp

processors:
batch:

service:
# extensions: [basicauth/otlp]
pipelines:
metrics:
receivers: [otlp, prometheus]
exporters: [otlphttp]
traces:
receivers: [otlp]
exporters: [otlphttp]
processors: [batch]
8 changes: 7 additions & 1 deletion deployment/overlays/local/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ resources:

images:
- name: ghcr.io/jrmanes/torch
newTag: v0.0.1
newTag: latest
- name: otel/opentelemetry-collector-contrib
newTag: 0.71.0

configMapGenerator:
- name: config
files:
- ./config/config.yaml
- name: otel-agent
files:
#- ./config/otel-agent.yaml
- ./config/otel-agent-celestia.yaml
29 changes: 21 additions & 8 deletions go.mod
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ module github.com/jrmanes/torch
go 1.20

require (
github.com/google/martian v2.1.0+incompatible
github.com/gorilla/mux v1.8.0
github.com/prometheus/client_golang v1.15.1
github.com/sirupsen/logrus v1.9.3
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/prometheus v0.39.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/sdk/metric v0.39.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.27.3
k8s.io/apimachinery v0.27.3
k8s.io/client-go v0.27.3
k8s.io/api v0.27.4
k8s.io/apimachinery v0.27.4
k8s.io/client-go v0.27.4
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand All @@ -28,18 +35,24 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.4.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
Expand Down
Loading

0 comments on commit 96ac7cc

Please sign in to comment.