-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an image with profiling enabled.
Signed-off-by: Vitaliy Guschin <[email protected]>
- Loading branch information
Vitaliy Guschin
committed
Jun 26, 2024
1 parent
e081e3d
commit f90edad
Showing
8 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,24 @@ ENV GO111MODULE=on | |
ENV CGO_ENABLED=0 | ||
ENV GOBIN=/bin | ||
ARG BUILDARCH=amd64 | ||
ARG ENABLE_PROFILER=false | ||
RUN go install github.com/go-delve/delve/cmd/[email protected] | ||
RUN go install github.com/grpc-ecosystem/[email protected] | ||
ADD https://github.com/spiffe/spire/releases/download/v1.8.0/spire-1.8.0-linux-${BUILDARCH}-musl.tar.gz . | ||
RUN tar xzvf spire-1.8.0-linux-${BUILDARCH}-musl.tar.gz -C /bin --strip=2 spire-1.8.0/bin/spire-server spire-1.8.0/bin/spire-agent | ||
|
||
|
||
FROM go as build | ||
WORKDIR /build | ||
COPY go.mod go.sum ./ | ||
COPY ./local ./local | ||
COPY ./internal/imports ./internal/imports | ||
RUN go build ./internal/imports | ||
COPY . . | ||
RUN go build -o /bin/nsmgr . | ||
RUN if [ "$ENABLE_PROFILER" = "true" ]; then \ | ||
go build -tags profiler -o /bin/nsmgr . ; \ | ||
else \ | ||
go build -o /bin/nsmgr . ; \ | ||
fi | ||
|
||
FROM build as test | ||
CMD go test -test.v ./... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !profiler | ||
|
||
package main | ||
|
||
import "context" | ||
|
||
func startProfiler(ctx context.Context, profilerHTTPPort uint16) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//go:build profiler | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
_ "net/http/pprof" // #nosec | ||
"time" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/tools/log" | ||
) | ||
|
||
func startProfiler(ctx context.Context, profilerHTTPPort uint16) { | ||
go func() { | ||
log.FromContext(ctx).Infof("Profiler is enabled. Starting HTTP server on %d", profilerHTTPPort) | ||
|
||
address := fmt.Sprintf("localhost:%d", profilerHTTPPort) | ||
|
||
server := &http.Server{ | ||
Addr: address, | ||
ReadTimeout: 10 * time.Second, | ||
WriteTimeout: 10 * time.Second, | ||
} | ||
|
||
if err := server.ListenAndServe(); err != nil { | ||
log.FromContext(ctx).Errorf("Failed to start profiler: %s", err.Error()) | ||
} | ||
}() | ||
} |