Skip to content

Commit

Permalink
Docker compose & Monitoring (#5)
Browse files Browse the repository at this point in the history
got docker-compose ready with prometheus, grafana and a basic latency metric.
  • Loading branch information
tufanbarisyildirim authored Mar 13, 2023
1 parent 6cb76cf commit b874674
Show file tree
Hide file tree
Showing 16 changed files with 375 additions and 44 deletions.
29 changes: 6 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,16 @@ FROM golang:latest as builder

# Set the working directory
WORKDIR /app

# Copy the go.mod and go.sum files
COPY go.mod go.sum ./

# Download the dependencies
RUN go mod download

# Copy the source code
COPY . .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /app/rpc-aggregator ./cmd/rpc-aggregator/main.go

# Build the binary
RUN go build -o rpc-aggregator cmd/rpc-aggregator/main.go

# Use a lightweight image as the final image
FROM alpine:latest

# Set the working directory
WORKDIR /app

# Copy the binary from the builder image
COPY --from=builder /app/rpc-aggregator .

# Copy the config.yaml file
COPY config.yaml .

# Expose the port the server will listen on
COPY --from=builder /app/rpc-aggregator /usr/local/bin/rpc-aggregator
COPY ./_private/solana.yaml /app/config.yaml
COPY ./_private/auth.yaml /app/auth.yaml
EXPOSE 8080

# Start the rpc-aggregator server
CMD ["./rpc-aggregator"]
#CMD ["/bin/sh"]
CMD ["/usr/local/bin/rpc-aggregator","--config","/app/config.yaml","--auth","/app/auth.yaml"]
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test:
.PHONY: check
check:
go mod verify
go build -v ./...
go vet ./...
staticcheck ./...
golint ./...
Expand Down
39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ flowchart LR
subgraph fasthttp
Routing --> Auth(Auth & Cors)
Auth --> Balancer
Balancer --> Proxy
end
Balancer --> Proxy
end
Proxy ---->|275ms| AS1[Provider 1]
Proxy -->|100ms| AS2[Provider 2]
Proxy --->|170ms| ASN[Provider N]
Proxy -->|TCP -> 100ms| Upstream1[Provider 1]
Proxy -->|TCP -> 101ms| Upstream2[Provider 2]
Proxy -->|TCP -> 200ms| Upstream3[Provider 3]
Proxy -->|TCP -> 300ms| Upstream4[Provider N]
```

if you are curious about details
Expand All @@ -46,7 +46,7 @@ if you are curious about details

### Phase 0: Release v0 ⌛️

- [ ] Distribute api keys for every project attends to [grizzlython](https://solana.com/grizzlython) with ability of;
- [x] Distribute api keys for every project attends to [grizzlython](https://solana.com/grizzlython) with ability of;
- [x] Api key auth & CORS
- [x] Rate limiting

Expand Down Expand Up @@ -94,6 +94,33 @@ info@rpc.ag
If you would like to contribute to the RPC Aggregator with load balancing, please fork the repository and create a pull
request with your changes. Be sure to include unit tests and adhere to the project's coding style.

Makefile Overview
-----------------

This project uses a Makefile to manage different actions related to the project, including building, running, testing, checking, creating a Docker image, running a Docker container, and cleaning. The following is a brief overview of each target in the Makefile:

- `build`: builds the project using the `go build` command and generates the binary file in the `bin/` directory
- `run`: runs the binary file generated by the `build` target and passes the configuration file as an argument
- `runp`: runs the binary file generated by the `build` target with a private configuration file located in the `_private/` directory
- `test`: tests the project using the `go test` command
- `check`: runs various checks on the project, including verifying the module dependencies, building, vetting, and linting the code
- `image`: builds a Docker image of the project using the `docker build` command
- `run-docker`: runs a Docker container of the project using the `docker run` command and maps port 8080
- `clean`: removes the binary file and the `bin/` directory

Usage
-----

1. Build the project using the `make build` command
2. Run the project using the `make run` or `make runp` command
3. Test the project using the `make test` command
4. Check the project using the `make check` command
5. Build a Docker image of the project using the `make image` command
6. Run a Docker container of the project using the `make run-docker` command
7. Clean the project using the `make clean` command

Note: Some Makefile targets require the `go`, `docker`, `staticcheck`, and `golint` commands to be installed.

> IF, the project get support (grant from any blockchain) to cover some server expenses and a bit more, we will share it
> to developers who contribute to rpc.ag at any level (proxy, doc, monitoring, etc) we will also open some grants for
> huge tasks and/or issues
Expand Down
13 changes: 12 additions & 1 deletion cmd/rpc-aggregator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"syscall"

"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rpc-ag/rpc-aggregator/internal/config"
"github.com/rpc-ag/rpc-aggregator/internal/webserver"
"go.uber.org/zap"
Expand Down Expand Up @@ -40,14 +42,23 @@ func main() {
server, err := webserver.New(conf, auth, logger)
if err != nil {
logger.Panic("failed to start webserver", zap.Error(err))
return
}

logger.Info("Starting RPC Aggregator...")

go func() {
er := server.Run()
if er != nil {
panic(er)
logger.Panic("failed to start server", zap.Error(er))
}
}()

go func() {
//move the port to the config
promErr := http.ListenAndServe(":9000", promhttp.Handler())
if promErr != nil {
logger.Panic("failed to start prim server", zap.Error(promErr))
}
}()

Expand Down
62 changes: 62 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
version: '3.8'

volumes:
prometheus_data: {}
grafana_data: {}

services:
aggregator:
container_name: aggregator
build:
context: .
dockerfile: Dockerfile
image: rpc-aggregator:latest
ports:
- 8080:8080 # proxy
- 9000:9000 # exporter
command: |
/usr/local/bin/rpc-aggregator --config /app/config.yaml --auth /app/auth.yaml
prometheus:
container_name: prometheus
image: prom/prometheus
restart: always
volumes:
- ./monitoring/prometheus:/etc/prometheus/
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
ports:
- 9090:9090
links:
- alertmanager:alertmanager
alertmanager:
container_name: alertmanager
image: prom/alertmanager
restart: always
ports:
- 9093:9093
volumes:
- ./monitoring/alertmanager/:/etc/alertmanager/
command:
- '--config.file=/etc/alertmanager/config.yml'
- '--storage.path=/alertmanager'
grafana:
container_name: grafana
image: grafana/grafana
user: '472'
restart: always
environment:
GF_INSTALL_PLUGINS: 'grafana-clock-panel,grafana-simple-json-datasource'
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/provisioning/:/etc/grafana/provisioning/
env_file:
- ./monitoring/grafana/config.monitoring
ports:
- 3000:3000
depends_on:
- prometheus
9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ require (

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -30,6 +38,7 @@ require (
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b874674

Please sign in to comment.