Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[event-watcher] Create service boilerplate #604

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
SHELL := /bin/bash


## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

build:
make -C analytics/ build
make -C api/ build
Expand All @@ -15,9 +8,10 @@ build:
make -C parser/ build
make -C tx-tracker/ build
make -C contract-watcher/ build
make -C event-watcher/ build

doc:
swag init -pd
make -C api/ doc

test:
cd analytics && go test -v -cover ./...
Expand All @@ -27,5 +21,6 @@ test:
cd parser && go test -v -cover ./...
cd tx-tracker && go test -v -cover ./...
cd contract-watcher && go test -v -cover ./...
cd event-watcher && go test -v -cover ./...

.PHONY: build doc test
48 changes: 48 additions & 0 deletions common/settings/structs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package settings

import (
"fmt"

"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)

// MongoDB contains configuration settings for a MongoDB database.
type MongoDB struct {
MongodbURI string `split_words:"true" required:"true"`
MongodbDatabase string `split_words:"true" required:"true"`
}

type Logger struct {
LogLevel string `split_words:"true" default:"INFO"`
}

type P2p struct {
P2pNetwork string `split_words:"true" required:"true"`
}

// Monitoring contains configuration settings for the monitoring endpoints.
type Monitoring struct {
// MonitoringPort defines the TCP port for the monitoring endpoints.
MonitoringPort string `split_words:"true" default:"8000"`
PprofEnabled bool `split_words:"true" default:"false"`
}

// LoadFromEnv loads the configuration settings from environment variables.
//
// If there is a .env file in the current directory, it will be used to
// populate the environment variables.
func LoadFromEnv[T any]() (*T, error) {

// Load .env file (if it exists)
_ = godotenv.Load()

// Load environment variables into a struct
var settings T
err := envconfig.Process("", &settings)
if err != nil {
return nil, fmt.Errorf("failed to read config from environment: %w", err)
}

return &settings, nil
}
20 changes: 20 additions & 0 deletions deploy/event-watcher/env/production-mainnet.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ENVIRONMENT=production-mainnet
NAMESPACE=wormscan
NAME=wormscan-event-watcher
REPLICAS=5
IMAGE_NAME=
RESOURCES_LIMITS_MEMORY=512Mi
RESOURCES_LIMITS_CPU=700m
RESOURCES_REQUESTS_MEMORY=384Mi
RESOURCES_REQUESTS_CPU=500m
AWS_IAM_ROLE=
P2P_NETWORK=mainnet
PPROF_ENABLED=false
MONITORING_PORT=8000
MONGODB_URI=
MONGODB_DATABASE=
LOG_LEVEL=INFO

ETHEREUM_REQUESTS_PER_MINUTE=12
ETHEREUM_URL=https://svc.blockdaemon.com/ethereum/mainnet/native
ETHEREUM_AUTH=
20 changes: 20 additions & 0 deletions deploy/event-watcher/env/production-testnet.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ENVIRONMENT=production-testnet
NAMESPACE=wormscan-testnet
NAME=wormscan-event-watcher
REPLICAS=3
IMAGE_NAME=
RESOURCES_LIMITS_MEMORY=256Mi
RESOURCES_LIMITS_CPU=500m
RESOURCES_REQUESTS_MEMORY=128Mi
RESOURCES_REQUESTS_CPU=250m
AWS_IAM_ROLE=
P2P_NETWORK=testnet
PPROF_ENABLED=false
MONITORING_PORT=8000
MONGODB_URI=
MONGODB_DATABASE=
LOG_LEVEL=INFO

ETHEREUM_REQUESTS_PER_MINUTE=12
ETHEREUM_URL=https://svc.blockdaemon.com/ethereum/goerli/native
ETHEREUM_AUTH=
20 changes: 20 additions & 0 deletions deploy/event-watcher/env/staging-mainnet.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ENVIRONMENT=staging-mainnet
NAMESPACE=wormscan
NAME=wormscan-event-watcher
REPLICAS=3
IMAGE_NAME=
RESOURCES_LIMITS_MEMORY=512Mi
RESOURCES_LIMITS_CPU=700m
RESOURCES_REQUESTS_MEMORY=384Mi
RESOURCES_REQUESTS_CPU=500m
AWS_IAM_ROLE=
P2P_NETWORK=mainnet
PPROF_ENABLED=false
MONITORING_PORT=8000
MONGODB_URI=
MONGODB_DATABASE=
LOG_LEVEL=INFO

ETHEREUM_REQUESTS_PER_MINUTE=12
ETHEREUM_URL=https://svc.blockdaemon.com/ethereum/mainnet/native
ETHEREUM_AUTH=
20 changes: 20 additions & 0 deletions deploy/event-watcher/env/staging-testnet.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ENVIRONMENT=staging-testnet
NAMESPACE=wormscan-testnet
NAME=wormscan-event-watcher
REPLICAS=2
IMAGE_NAME=
RESOURCES_LIMITS_MEMORY=256Mi
RESOURCES_LIMITS_CPU=500m
RESOURCES_REQUESTS_MEMORY=128Mi
RESOURCES_REQUESTS_CPU=250m
AWS_IAM_ROLE=
P2P_NETWORK=testnet
PPROF_ENABLED=false
MONITORING_PORT=8000
MONGODB_URI=
MONGODB_DATABASE=
LOG_LEVEL=INFO

ETHEREUM_REQUESTS_PER_MINUTE=12
ETHEREUM_URL=https://svc.blockdaemon.com/ethereum/goerli/native
ETHEREUM_AUTH=
75 changes: 75 additions & 0 deletions deploy/event-watcher/event-watcher-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .NAME }}
namespace: {{ .NAMESPACE }}
spec:
replicas: {{ .REPLICAS }}
selector:
matchLabels:
app: {{ .NAME }}
template:
metadata:
labels:
app: {{ .NAME }}
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
spec:
restartPolicy: Always
terminationGracePeriodSeconds: 40
serviceAccountName: event-watcher
containers:
- name: {{ .NAME }}
image: {{ .IMAGE_NAME }}
imagePullPolicy: Always
readinessProbe:
initialDelaySeconds: 30
periodSeconds: 20
timeoutSeconds: 3
failureThreshold: 3
httpGet:
path: /api/ready
port: 8000
livenessProbe:
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 3
failureThreshold: 3
httpGet:
path: /api/health
port: 8000
env:
- name: ENVIRONMENT
value: {{ .ENVIRONMENT }}
- name: MONITORING_PORT
value: "{{ .MONITORING_PORT }}"
- name: LOG_LEVEL
value: "{{ .LOG_LEVEL }}"
- name: ETHEREUM_REQUESTS_PER_MINUTE
value: "{{ .ETHEREUM_REQUESTS_PER_MINUTE }}"
- name: ETHEREUM_URL
value: "{{ .ETHEREUM_URL }}"
- name: ETHEREUM_AUTH
value: "{{ .ETHEREUM_AUTH }}"
- name: MONGODB_URI
valueFrom:
secretKeyRef:
name: mongodb
key: mongo-uri
- name: MONGODB_DATABASE
valueFrom:
configMapKeyRef:
name: config
key: mongo-database
- name: P2P_NETWORK
value: {{ .P2P_NETWORK }}
- name: PPROF_ENABLED
value: "{{ .PPROF_ENABLED }}"
resources:
limits:
memory: {{ .RESOURCES_LIMITS_MEMORY }}
cpu: {{ .RESOURCES_LIMITS_CPU }}
requests:
memory: {{ .RESOURCES_REQUESTS_MEMORY }}
cpu: {{ .RESOURCES_REQUESTS_CPU }}
7 changes: 7 additions & 0 deletions deploy/event-watcher/sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: event-watcher
namespace: {{ .NAMESPACE }}
annotations:
eks.amazonaws.com/role-arn: {{ .AWS_IAM_ROLE }}
2 changes: 2 additions & 0 deletions event-watcher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin/service
.env
21 changes: 21 additions & 0 deletions event-watcher/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# syntax=docker.io/docker/dockerfile:1.3@sha256:42399d4635eddd7a9b8a24be879d2f9a930d0ed040a61324cfdf59ef1357b3b2
FROM --platform=linux/amd64 docker.io/golang:1.19.2@sha256:0467d7d12d170ed8d998a2dae4a09aa13d0aa56e6d23c4ec2b1e4faacf86a813 AS build

WORKDIR /app

COPY event-watcher event-watcher
COPY common common

# Build the Go app
RUN cd event-watcher && CGO_ENABLED=0 GOOS=linux go build -o "./service" cmd/service/main.go

############################
# STEP 2 build a small image
############################
FROM alpine
#Copy certificates
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy our static executable.
COPY --from=build "/app/event-watcher/service" "/service"
# Run the binary.
ENTRYPOINT ["/service"]
9 changes: 9 additions & 0 deletions event-watcher/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

build:
CGO_ENABLED=0 GOOS=linux go build -o "./bin/service" cmd/service/main.go

test:
go test -v -cover ./...


.PHONY: build test
Empty file added event-watcher/bin/.gitkeep
Empty file.
Loading
Loading