Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
feat: add probe docker
Browse files Browse the repository at this point in the history
  • Loading branch information
GalvinGao committed Apr 17, 2022
1 parent 16bb3d4 commit 6a1ee57
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web/* linguist-vendored
web/* linguist-vendored
33 changes: 33 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Build Docker Image

on:
push:
# trigger on any tag push
tags:
- "**"

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Get Tag Version
id: get_version
run: |
export TRUNCATED_GITHUB_SHA=$(echo ${{ github.sha }} | cut -c1-7);
echo "VERSION=${GITHUB_REF/refs\/tags\//}+${TRUNCATED_GITHUB_SHA}" >> $GITHUB_ENV
echo "GIT_TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Build and Publish to Registry
uses: elgohr/[email protected]
with:
name: penguin-statistics/probe
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
tags: "latest,${{ env.GIT_TAG }}"
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM golang:1.18.1-alpine AS base
WORKDIR /app

# builder
FROM base AS gobuilder
ENV GOOS linux
ENV GOARCH amd64

# go 1.18 requires git
RUN apk add --no-cache git

# modules: utilize build cache
COPY go.mod ./
COPY go.sum ./

# RUN go env -w GO111MODULE=on && go env -w GOPROXY=https://goproxy.cn,direct
RUN go mod download
COPY . .

# build the binary
RUN go build -o probe .

# runner
FROM base AS runner
RUN apk add --no-cache libc6-compat tini
# Tini is now available at /sbin/tini

COPY --from=gobuilder /app/probe /app/probe
COPY --from=gobuilder /app/config.example.yml /app/config.yml

ENTRYPOINT ["/sbin/tini", "--"]
CMD [ "/app/probe" ]
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
init:
go get -v ./...
go get github.com/cespare/reflex
go install github.com/mitranim/gow@latest

dev:
reflex -d none -t 1s -s -R vendor. -r '\.(go|yml)$$' -- sh -c 'PENGUIN_PROBE_PPROF=1 go run ./cmd'
gow -c -e go,yml,mod run ./cmd

protoc:
protoc -I=internal/pkg/messages/ --go_out=internal/pkg/messages/ internal/pkg/messages/*.proto
Expand Down
7 changes: 4 additions & 3 deletions cmd/analytics.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package main
package cmd

import (
"fmt"
"github.com/penguin-statistics/probe/internal/app/server"
"net/http"
_ "net/http/pprof"
"os"

"github.com/penguin-statistics/probe/internal/app/server"
)

func main() {
func Bootstrap() {
if os.Getenv("PENGUIN_PROBE_PPROF") == "1" {
go func() {
fmt.Println("pprof enabled")
Expand Down
File renamed without changes.
15 changes: 10 additions & 5 deletions internal/pkg/wspool/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package wspool

import (
"errors"
"time"

"github.com/gorilla/websocket"
"github.com/penguin-statistics/probe/internal/pkg/messages"
"go.uber.org/ratelimit"
"google.golang.org/protobuf/proto"
"time"

"github.com/penguin-statistics/probe/internal/pkg/messages"
)

const (
// Time allowed to write a message to the peer.
writeWait = 30 * time.Second
writeWait = 5 * time.Second

// Time allowed to read the next pong message from the peer.
pongWait = 60 * time.Minute
Expand All @@ -26,6 +28,8 @@ const (
maxRPS = 20
)

var ErrInvalidMessageType = errors.New("invalid message type")

// ClientRequest is the skeleton-unmarshalled client side request
type ClientRequest struct {
Skeleton *messages.Skeleton
Expand Down Expand Up @@ -113,7 +117,7 @@ func (c *Client) readSkeleton() (s *messages.Skeleton, p []byte, err error) {
}
if typ != websocket.BinaryMessage && typ != websocket.PongMessage {
c.Hub.logger.Debugln("unexpected message type that is not a BinaryMessage type", typ)
return &messages.Skeleton{}, nil, errors.New("unexpected message type")
return &messages.Skeleton{}, nil, ErrInvalidMessageType
}

var skeleton messages.Skeleton
Expand All @@ -137,6 +141,7 @@ func (c *Client) Write() {
c.Hub.logger.Traceln("starting ping ticker with period of", pingPeriod)
pingTicker := time.NewTicker(pingPeriod)
defer func() {
c.Hub.logger.Traceln("stopping writer")
pingTicker.Stop()
c.Close()
}()
Expand All @@ -149,7 +154,7 @@ func (c *Client) Write() {
err := c.Conn.WritePreparedMessage(message)
if err != nil {
c.Hub.logger.Debugln("failed to send message", err)
c.InvalidCount++
return
}
c.Hub.logger.Traceln("ws data sent")
case <-pingTicker.C:
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/penguin-statistics/probe/cmd"

func main() {
cmd.Bootstrap()
}

0 comments on commit 6a1ee57

Please sign in to comment.