diff --git a/go/Makefile b/go/Makefile index 35abab1..a8210da 100644 --- a/go/Makefile +++ b/go/Makefile @@ -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; \ diff --git a/go/assets/mock_data.go b/go/assets/mock_data.go new file mode 100644 index 0000000..d8c61e6 --- /dev/null +++ b/go/assets/mock_data.go @@ -0,0 +1,8 @@ +//go:build !prod + +package assets + +import "embed" + +//go:embed mock-data +var MockData embed.FS diff --git a/go/assets/assets.go b/go/assets/web.go similarity index 80% rename from go/assets/assets.go rename to go/assets/web.go index b9ed567..dbeefd4 100644 --- a/go/assets/assets.go +++ b/go/assets/web.go @@ -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 diff --git a/go/internal/live-pprof.go b/go/internal/live-pprof.go index df2b98e..6b7e514 100644 --- a/go/internal/live-pprof.go +++ b/go/internal/live-pprof.go @@ -16,10 +16,6 @@ import ( "google.golang.org/grpc" ) -func main() { - -} - func LivePprof() { conf := config.ParseLPFlags() diff --git a/go/internal/metrics/mock_assets.go b/go/internal/metrics/mock_assets.go index 7408a70..bcecdc6 100644 --- a/go/internal/metrics/mock_assets.go +++ b/go/internal/metrics/mock_assets.go @@ -1,3 +1,5 @@ +//go:build !prod + package metrics import ( diff --git a/go/internal/metrics/mock_metrics_server.go b/go/internal/metrics/mock_metrics_server.go index dc03521..fa10e7b 100644 --- a/go/internal/metrics/mock_metrics_server.go +++ b/go/internal/metrics/mock_metrics_server.go @@ -1,3 +1,4 @@ +//go:build !prod package metrics import ( diff --git a/go/internal/metrics/mock_metrics_server_prod.go b/go/internal/metrics/mock_metrics_server_prod.go new file mode 100644 index 0000000..7153557 --- /dev/null +++ b/go/internal/metrics/mock_metrics_server_prod.go @@ -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 +}