Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ LOCAL_DEV ?= ./misc/local-dev.sh
setup:
@$(LOCAL_DEV) setup-loopback $(TSURU_HOST_IP)
@$(DOCKER_COMPOSE) up -d
@$(GO) install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.6
@$(GO) install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1

.PHONY: cleanup
cleanup:
Expand All @@ -29,12 +31,12 @@ test: generate

.PHONY: test/integration
test/integration:
DEPLOY_AGENT_INTEGRATION=true \
DEPLOY_AGENT_INTEGRATION_REGISTRY_HOST=$(INTERNAL_IP):5000 \
DEPLOY_AGENT_INTEGRATION_REGISTRY_HTTP=true \
BUILDKIT_HOST=tcp://0.0.0.0:7777 \
DOCKER_HOST=tcp://0.0.0.0:2375 \
$(GO) test -v github.com/tsuru/deploy-agent/pkg/build/buildkit
DEPLOY_AGENT_INTEGRATION=true \
Comment thread
ravilock marked this conversation as resolved.
Outdated
DEPLOY_AGENT_INTEGRATION_REGISTRY_HOST=$(INTERNAL_IP):5000 \
DEPLOY_AGENT_INTEGRATION_REGISTRY_HTTP=true \
BUILDKIT_HOST=tcp://0.0.0.0:7777 \
DOCKER_HOST=tcp://0.0.0.0:2375 \
$(GO) test -v github.com/tsuru/deploy-agent/pkg/build/buildkit
Comment thread
ravilock marked this conversation as resolved.
Outdated

.PHONY: lint
lint: generate
Expand Down
31 changes: 18 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ require (
github.com/google/go-containerregistry v0.12.0
github.com/moby/buildkit v0.11.3
github.com/oracle/oci-go-sdk/v65 v65.73.0
github.com/prometheus/client_golang v1.23.2
github.com/stretchr/testify v1.11.1
golang.org/x/sync v0.12.0
golang.org/x/sync v0.16.0
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.36.8
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
Expand All @@ -28,6 +29,8 @@ require (
cloud.google.com/go/compute/metadata v0.3.0 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/Microsoft/hcsshim v0.9.12 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/containerd/containerd v1.6.38 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/errdefs v0.1.0 // indirect
Expand All @@ -50,16 +53,14 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/patternmatcher v0.5.0 // indirect
Expand All @@ -74,6 +75,9 @@ require (
github.com/opencontainers/selinux v1.11.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sony/gobreaker v0.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -87,15 +91,16 @@ require (
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v0.12.0 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sys v0.31.0 // indirect
golang.org/x/term v0.30.0 // indirect
golang.org/x/text v0.23.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
golang.org/x/crypto v0.41.0 // indirect
golang.org/x/mod v0.26.0 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.30.0 // indirect
golang.org/x/sys v0.35.0 // indirect
golang.org/x/term v0.34.0 // indirect
golang.org/x/text v0.28.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/tools v0.35.0 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
Expand Down
73 changes: 45 additions & 28 deletions go.sum

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
"fmt"
"math"
"net"
"net/http"
"os"
"os/signal"
"syscall"
"time"

"github.com/moby/buildkit/client"
"github.com/prometheus/client_golang/prometheus/promhttp"
"google.golang.org/grpc"
healthpb "google.golang.org/grpc/health/grpc_health_v1"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -48,6 +50,7 @@ var cfg struct {
BuildKitAutoDiscoveryTimeout time.Duration
BuildKitAutoDiscoveryKubernetesPort int
Port int
MetricsPort int
ServerMaxRecvMsgSize int
ServerMaxSendMsgSize int
BuildKitAutoDiscoveryScaleGracefulPeriod time.Duration
Expand All @@ -61,6 +64,7 @@ func main() {
klog.InitFlags(flag.CommandLine)

flag.IntVar(&cfg.Port, "port", 8080, "Server TCP port")
flag.IntVar(&cfg.MetricsPort, "metrics-port", 9090, "Metrics server TCP port")
flag.IntVar(&cfg.ServerMaxRecvMsgSize, "max-receiving-message-size", DefaultServerMaxRecvMsgSize, "Max message size in bytes that server can receive")
flag.IntVar(&cfg.ServerMaxSendMsgSize, "max-sending-message-size", DefaultServerMaxSendMsgSize, "Max message size in bytes that server can send")

Expand Down Expand Up @@ -108,6 +112,7 @@ func main() {
buildpb.RegisterBuildServer(s, build.NewServer(bk))
healthpb.RegisterHealthServer(s, health.NewServer())

go startMetricsServer(cfg.MetricsPort)
go handleGracefulTermination(s)

fmt.Println("Starting gRPC server at", l.Addr().String())
Expand All @@ -120,6 +125,21 @@ func main() {
fmt.Println("gRPC server terminated")
}

func startMetricsServer(port int) {
http.Handle("/metrics", promhttp.Handler())
addr := fmt.Sprintf(":%d", port)
fmt.Println("Starting metrics server at", addr)
server := &http.Server{
Addr: addr,
ReadTimeout: 5 * time.Second,
ReadHeaderTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
fmt.Fprintf(os.Stderr, "failed to start metrics server: %v\n", err)
Comment thread
ravilock marked this conversation as resolved.
}
}
Comment thread
ravilock marked this conversation as resolved.

func handleGracefulTermination(s *grpc.Server) {
defer func() {
fmt.Fprintln(os.Stdout, "Received termination signal. Terminating gRPC server...")
Expand Down
Loading
Loading