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

[PROTO-1417] Expose uptime via /up route (no styling) #6627

Merged
merged 2 commits into from
Nov 9, 2023
Merged
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
5 changes: 5 additions & 0 deletions .circleci/src/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ jobs:
context: [GCP, dockerhub, slack-secrets]
service: dashboard
notify_slack_on_failure: true
- push-docker-image:
name: push-uptime
context: [Vercel, dockerhub]
service: uptime
notify_slack_on_failure: true

- push-arm-image:
name: push-discovery-provider-arm
Expand Down
1 change: 1 addition & 0 deletions mediorum/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ FROM golang:alpine AS builder
RUN apk add build-base make ffmpeg

WORKDIR /app
ENV CGO_ENABLED=0

COPY go.mod go.sum ./
RUN go mod graph | awk '{if ($1 !~ "@") print $2}' | xargs go get
Expand Down
1 change: 1 addition & 0 deletions mediorum/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install 'web3==6.6.1'

WORKDIR /app
ENV CGO_ENABLED=0

RUN go install github.com/cosmtrek/air@latest

Expand Down
30 changes: 30 additions & 0 deletions mediorum/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,22 @@ func New(config MediorumConfig) (*MediorumServer, error) {
healthzProxy := httputil.NewSingleHostReverseProxy(healthzUrl)
healthz.Any("*", echo.WrapHandler(healthzProxy))

// -------------------
// reverse proxy /up and /up_api to uptime container
uptimeUrl, err := url.Parse("http://uptime:1996")
if err != nil {
log.Fatal("Invalid uptime URL: ", err)
}
uptimeProxy := httputil.NewSingleHostReverseProxy(uptimeUrl)

uptimeAPI := routes.Group("/up_api")
// fixes what I think should be considered an echo bug: https://github.com/labstack/echo/issues/1419
uptimeAPI.Use(ACAOHeaderOverwriteMiddleware)
uptimeAPI.Any("/*", echo.WrapHandler(uptimeProxy))

uptimeUI := routes.Group("/up")
uptimeUI.Any("*", echo.WrapHandler(uptimeProxy))

// -------------------
// internal
internalApi := routes.Group("/internal")
Expand Down Expand Up @@ -353,6 +369,20 @@ func New(config MediorumConfig) (*MediorumServer, error) {

}

func setResponseACAOHeaderFromRequest(req http.Request, resp echo.Response) {
resp.Header().Set(echo.HeaderAccessControlAllowOrigin,
req.Header.Get(echo.HeaderOrigin))
}

func ACAOHeaderOverwriteMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
ctx.Response().Before(func() {
setResponseACAOHeaderFromRequest(*ctx.Request(), *ctx.Response())
})
return next(ctx)
}
}

func (ss *MediorumServer) MustStart() {

// start pprof server
Expand Down
27 changes: 22 additions & 5 deletions monitoring/uptime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
FROM golang:1.21.4-alpine AS builder
# Stage 1: Build the React app
FROM node:18-alpine as react-builder

ENV UPTIME_BASE_URL="/up/"
WORKDIR /app
COPY node-ui/package.json node-ui/package-lock.json ./node-ui/
RUN npm install --prefix node-ui

COPY node-ui/ ./node-ui/
RUN npm run build --prefix node-ui

# Stage 2: Build the Go binary
FROM golang:1.21.4-alpine AS go-builder

WORKDIR /app

# Cache deps before copying source and building
COPY go.mod go.sum ./
ENV CGO_ENABLED=0
# Cache deps before building and copying source
RUN go mod download

COPY . .
RUN go build -o /uptime
RUN CGO_ENABLED=0 go build -o /uptime

# Stage 3: Copy the binary and static assets to a minimal final image
FROM alpine:3.18.4 AS final
RUN apk add --no-cache curl
COPY --from=builder /uptime /bin/uptime
COPY --from=go-builder /uptime /bin/uptime
COPY --from=react-builder /app/node-ui/dist /app/node-ui/dist

ENTRYPOINT ["/bin/uptime"]
4 changes: 4 additions & 0 deletions monitoring/uptime/node-ui/.env.stage.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# For testing staging locally (ie, npm run stage)
VITE_ENV_OVERRIDE=stage
VITE_NODE_TYPE_OVERRIDE=discovery
VITE_NODE_URL_OVERRIDE=https://discoveryprovider3.staging.audius.co
27 changes: 27 additions & 0 deletions monitoring/uptime/node-ui/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended-type-checked',
'plugin:react-hooks/recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',

],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
26 changes: 26 additions & 0 deletions monitoring/uptime/node-ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

!.env.stage.local
1 change: 1 addition & 0 deletions monitoring/uptime/node-ui/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.0
6 changes: 6 additions & 0 deletions monitoring/uptime/node-ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Node UI

React app exposing uptime of nodes in the network.

To test locally: `npm run stage` or `npm run prod`.
When ran on stage or prod, the app will query its local /up_api/env endpoint to get environment variables that are set on the node (because the React app can't access these directly for security reasons).
13 changes: 13 additions & 0 deletions monitoring/uptime/node-ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="shortcut icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Node UI</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
Loading