Skip to content

Commit

Permalink
chore: reduce binary size (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
clement2026 authored Sep 5, 2024
1 parent 7868f8d commit f070475
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 14 deletions.
14 changes: 7 additions & 7 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ protoc:

build:
@echo "Building go"
go build -o build/${BINARY_NAME} ${ENTRY}
go build -tags prod -o build/${BINARY_NAME} ${ENTRY}

build-for-release:
@echo "Building go for release"
GOOS=linux GOARCH=amd64 go build -o build/${BINARY_NAME}-linux-amd64 ${ENTRY};
GOOS=linux GOARCH=arm64 go build -o build/${BINARY_NAME}-linux-arm64 ${ENTRY};
GOOS=darwin GOARCH=amd64 go build -o build/${BINARY_NAME}-darwin-amd64 ${ENTRY};
GOOS=darwin GOARCH=arm64 go build -o build/${BINARY_NAME}-darwin-arm64 ${ENTRY};
GOOS=windows GOARCH=amd64 go build -o build/${BINARY_NAME}-windows-amd64.exe ${ENTRY};
GOOS=windows GOARCH=arm64 go build -o build/${BINARY_NAME}-windows-arm64.exe ${ENTRY};
GOOS=linux GOARCH=amd64 go build -tags prod -o build/${BINARY_NAME}-linux-amd64 ${ENTRY};
GOOS=linux GOARCH=arm64 go build -tags prod -o build/${BINARY_NAME}-linux-arm64 ${ENTRY};
GOOS=darwin GOARCH=amd64 go build -tags prod -o build/${BINARY_NAME}-darwin-amd64 ${ENTRY};
GOOS=darwin GOARCH=arm64 go build -tags prod -o build/${BINARY_NAME}-darwin-arm64 ${ENTRY};
GOOS=windows GOARCH=amd64 go build -tags prod -o build/${BINARY_NAME}-windows-amd64.exe ${ENTRY};
GOOS=windows GOARCH=arm64 go build -tags prod -o build/${BINARY_NAME}-windows-arm64.exe ${ENTRY};
cd build; \
tar -zcvf ${BINARY_NAME}-linux-amd64.tar.gz ${BINARY_NAME}-linux-amd64; \
tar -zcvf ${BINARY_NAME}-linux-arm64.tar.gz ${BINARY_NAME}-linux-arm64; \
Expand Down
8 changes: 8 additions & 0 deletions go/assets/mock_data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !prod

package assets

import "embed"

//go:embed mock-data
var MockData embed.FS
3 changes: 0 additions & 3 deletions go/assets/assets.go → go/assets/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package assets

import "embed"

//go:embed mock-data
var MockData embed.FS

// Web The all: prefix (added in Go 1.18) ensures that any files or directories prefixed with . or _ are included:
//
//go:embed all:web
Expand Down
4 changes: 0 additions & 4 deletions go/internal/live-pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import (
"google.golang.org/grpc"
)

func main() {

}

func LivePprof() {
conf := config.ParseLPFlags()

Expand Down
2 changes: 2 additions & 0 deletions go/internal/metrics/mock_assets.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !prod

package metrics

import (
Expand Down
1 change: 1 addition & 0 deletions go/internal/metrics/mock_metrics_server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !prod
package metrics

import (
Expand Down
42 changes: 42 additions & 0 deletions go/internal/metrics/mock_metrics_server_prod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build prod

package metrics

import (
"context"
"errors"

"github.com/moderato-app/live-pprof/api"
"github.com/moderato-app/live-pprof/internal/logging"
)

var mockNotAvailableErr = errors.New("mock data is not available for a prod build")

// MockMetricsServer returns mock data instead of real data to save development time
type MockMetricsServer struct {
api.UnimplementedMockMetricsServer
}

func NewMockMetricsServer() *MockMetricsServer {
return &MockMetricsServer{}
}

func (m *MockMetricsServer) HeapMetrics(_ context.Context, req *api.GoMetricsRequest) (*api.GoMetricsResponse, error) {
logging.Sugar.Debug("HeapMetrics req:", req)
return nil, mockNotAvailableErr
}

func (m *MockMetricsServer) CPUMetrics(_ context.Context, req *api.GoMetricsRequest) (*api.GoMetricsResponse, error) {
logging.Sugar.Debug("CPUMetrics req:", req)
return nil, mockNotAvailableErr
}

func (m *MockMetricsServer) AllocsMetrics(_ context.Context, req *api.GoMetricsRequest) (*api.GoMetricsResponse, error) {
logging.Sugar.Debug("AllocsMetrics req:", req)
return nil, mockNotAvailableErr
}

func (m *MockMetricsServer) GoroutineMetrics(_ context.Context, req *api.GoMetricsRequest) (*api.GoMetricsResponse, error) {
logging.Sugar.Debug("GoroutineMetrics req:", req)
return nil, mockNotAvailableErr
}

0 comments on commit f070475

Please sign in to comment.