mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-06-05 23:03:48 +00:00
c2c75d69c0
Performance / resource usage: - circuit_breaker_metrics: fix data race on failCounters map (RWMutex + double-checked locking) - server.go: drop user_id and op_name metric labels (Prometheus cardinality bound); de-duplicate extractUserInfo - graphql.go: gate runtime.ReadMemStats per-request behind ENABLE_ALLOCATION_TRACKING flag (default off) - graphql.go: collapse two-pass AST scan into single pass; lower-case once - sanitization.go: cache compiled redaction regexes per pattern via sync.Map; hoist inner constants to pkg vars - proxy.go: hoist connection/timeout substrings to pkg vars; sentinel errors for static error paths; drop dead Headers map alloc - metrics_aggregator.go: log-field allocation guarded by Logger.IsLevelEnabled - logging/logger.go: add IsLevelEnabled helper - lru_cache.go: 16-shard sharding, FNV-1a routing (concurrent throughput +22%) - cache/memory/lru_memory_cache.go: gzip compress/decompress moved outside mu.Lock - rps_tracker.go: RWMutex+uint64 -> atomic.Uint64 - retry_budget.go: drop unused mutex - api.go: bannedUsersIDs map+RWMutex -> sync.Map (+ snapshot/replace helpers) - tracing/tracing.go: pkg-level constSpanAttrs, copy-then-append in StartSpanWithAttributes - admin_dashboard.go: handleStatsWebSocket reuses bytes.Buffer + json.Encoder per connection Build / runtime: - Makefile: -ldflags="-s -w" -trimpath, CGO_ENABLED=0 for build (=1 for test recipes) - Dockerfile + Dockerfile.goreleaser: ENV GOMEMLIMIT=512MiB - main.go: blank import go.uber.org/automaxprocs (cgroup-aware GOMAXPROCS) - main.go: PPROF_PORT env var wires net/http/pprof on 127.0.0.1 only with full server timeouts - README.md: env-var docs + metric-label docs updated; cardinality note Test coverage push (per package): - main 51.2% -> 74.7% - cache 66.3% -> 93.7% - cache/redis 45.5% -> 98.2% - tracing 66.7% -> 72.9% - (cache/memory 91.6%, logging 91.9%, monitoring 77.6%, pkg/pools 100% unchanged) New test files: coverage_micro_test, coverage_extras_test, server_handlers_test, api_health_test, admin_dashboard_cluster_test, metrics_aggregator_test, concerns_test, cache/cache_coverage_test, cache/redis/redis_coverage_test, tracing/tracing_coverage_test. Bug fix: connection_resilience_test.go TestIntegratedHealthManagement.health_manager_startup was sync.Once-coupled to InitializeBackendHealth and panicked when another test (e.g. via parseConfig) had already triggered Once. Use NewBackendHealthManager directly.
67 lines
2.3 KiB
Makefile
67 lines
2.3 KiB
Makefile
CI_RUN?=false
|
|
TIMESTAMP := $(shell date +%Y%m%d-%H%M%S)
|
|
|
|
# Build hardening flags
|
|
# -s: omit symbol table, -w: omit DWARF debug info (smaller binaries)
|
|
LDFLAGS ?= -s -w
|
|
# -trimpath: remove local filesystem paths from binary (reproducible builds)
|
|
GOFLAGS ?= -trimpath
|
|
# CGO_ENABLED=0: static binary, no libc dependency (distroless-friendly)
|
|
export CGO_ENABLED = 0
|
|
|
|
# ADDITIONAL_BUILD_FLAGS=""
|
|
|
|
# ifeq ($(CI_RUN), true)
|
|
# ADDITIONAL_BUILD_FLAGS="-test.short"
|
|
# endif
|
|
|
|
.PHONY: help
|
|
help: ## display this help
|
|
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
|
|
|
|
.PHONY: run
|
|
run: build ## run application
|
|
@LOG_LEVEL=debug PURGE_METRICS_ON_CRAWL=true BLOCK_SCHEMA_INTROSPECTION=true CACHE_TTL=10 JWT_ROLE_RATE_LIMIT=false JWT_ROLE_CLAIM_PATH="Hasura.x-hasura-default-role" JWT_USER_CLAIM_PATH="Hasura.x-hasura-user-id" HOST_GRAPHQL=https://hasura8.lan/ HEALTHCHECK_GRAPHQL_URL=https://hasura8.lan/v1/graphql MONITORING_PORT=8222 PORT_GRAPHQL=8111 ./graphql-proxy
|
|
|
|
.PHONY: build
|
|
build: ## build the binary
|
|
go build $(GOFLAGS) -ldflags="$(LDFLAGS)" -o graphql-proxy *.go
|
|
|
|
.PHONY: test
|
|
test: ## run tests on library
|
|
@CGO_ENABLED=1 LOG_LEVEL=info go test -v -cover -race ./...
|
|
|
|
.PHONY: test-packages
|
|
test-packages: ## run tests on packages
|
|
@CGO_ENABLED=1 go test -v -cover -race ./pkg/...
|
|
|
|
.PHONY: all
|
|
all: test-packages test
|
|
|
|
.PHONY: update
|
|
update: ## update dependencies
|
|
@go get -u -v ./...
|
|
@go mod tidy -v
|
|
|
|
.PHONY: build-amd64
|
|
build-amd64: ## build the Linux AMD64 binary
|
|
GOOS=linux GOARCH=amd64 go build $(GOFLAGS) -ldflags="$(LDFLAGS)" -o graphql-proxy-amd64 *.go
|
|
|
|
.PHONY: build-arm64
|
|
build-arm64: ## build the Linux ARM64 binary
|
|
GOOS=linux GOARCH=arm64 go build $(GOFLAGS) -ldflags="$(LDFLAGS)" -o graphql-proxy-arm64 *.go
|
|
|
|
.PHONY: build-all
|
|
build-all: build-amd64 build-arm64 ## build both AMD64 and ARM64 binaries
|
|
|
|
.PHONY: docker
|
|
docker: build-all ## build multi-arch (AMD64 and ARM64) docker image
|
|
@mkdir -p dist
|
|
@mv graphql-proxy-amd64 dist/bot-linux-amd64
|
|
@mv graphql-proxy-arm64 dist/bot-linux-arm64
|
|
@docker buildx build --push \
|
|
--platform linux/amd64,linux/arm64 \
|
|
-t ghcr.io/lukaszraczylo/graphql-monitoring-proxy:local-test-build-$(TIMESTAMP) \
|
|
.
|
|
|