Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pprof profiling #329

Merged
merged 1 commit into from Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -8,19 +8,21 @@ IMAGE_VERSION ?= 0.0.10
IMAGE_NAME ?= secrets-store-csi-driver-provider-azure

BUILD_DATE=$$(date +%Y-%m-%d-%H:%M)
BUILD_COMMIT := $$(git rev-parse --short HEAD)
GO_FILES=$(shell go list ./...)
ORG_PATH=github.com/Azure
REPO_PATH="$(ORG_PATH)/$(IMAGE_NAME)"
E2E_IMAGE_TAG=$(REGISTRY)/$(IMAGE_NAME):$(IMAGE_VERSION)

BUILD_DATE_VAR := $(REPO_PATH)/pkg/version.BuildDate
BUILD_VERSION_VAR := $(REPO_PATH)/pkg/version.BuildVersion
VCS_VAR := $(REPO_PATH)/pkg/version.Vcs

ALL_DOCS := $(shell find . -name '*.md' -type f | sort)
TOOLS_MOD_DIR := ./tools
TOOLS_DIR := $(abspath ./.tools)

LDFLAGS ?= "-X $(BUILD_DATE_VAR)=$(BUILD_DATE) -X $(BUILD_VERSION_VAR)=$(IMAGE_VERSION)"
LDFLAGS ?= "-X $(BUILD_DATE_VAR)=$(BUILD_DATE) -X $(BUILD_VERSION_VAR)=$(IMAGE_VERSION) -X $(VCS_VAR)=$(BUILD_COMMIT)"

GO111MODULE ?= on
export GO111MODULE
Expand Down
14 changes: 14 additions & 0 deletions cmd/main.go
@@ -1,7 +1,10 @@
package main

import (
"fmt"
"net"
"net/http"
_ "net/http/pprof" // #nosec
"os"
"os/signal"
"runtime"
Expand All @@ -23,6 +26,8 @@ var (
versionInfo = pflag.Bool("version", false, "prints the version information")
endpoint = pflag.String("endpoint", "unix:///tmp/azure.sock", "CSI gRPC endpoint")
logFormatJSON = pflag.Bool("log-format-json", false, "set log formatter to json")
enableProfile = pflag.Bool("enable-pprof", false, "enable pprof profiling")
profilePort = pflag.Int("pprof-port", 6060, "port for pprof profiling")
)

func main() {
Expand All @@ -38,12 +43,21 @@ func main() {
klog.SetLogger(json.JSONLogger)
}

klog.Infof("Starting Azure Key Vault Provider version: %s", version.BuildVersion)
if *versionInfo {
if err := version.PrintVersion(); err != nil {
klog.Fatalf("failed to print version, err: %+v", err)
}
os.Exit(0)
}
if *enableProfile {
klog.Infof("Starting profiling on port %d", *profilePort)
go func() {
addr := fmt.Sprintf("%s:%d", "localhost", *profilePort)
klog.ErrorS(http.ListenAndServe(addr, nil), "unable to start profiling server")
}()
}

// Add csi-secrets-store user agent to adal requests
if err := adal.AddToUserAgent(version.GetUserAgent()); err != nil {
klog.Fatalf("failed to add user agent to adal: %+v", err)
Expand Down
5 changes: 4 additions & 1 deletion pkg/version/version.go
Expand Up @@ -3,13 +3,16 @@ package version
import (
"encoding/json"
"fmt"
"runtime"
)

var (
// BuildDate is date when binary was built
BuildDate string
// BuildVersion is the version of binary
BuildVersion string
// Vcs is is the commit hash for the binary build
Vcs string

minDriverVersion = "v0.0.8"
)
Expand Down Expand Up @@ -40,5 +43,5 @@ func PrintVersion() (err error) {

// GetUserAgent returns UserAgent string to append to the agent identifier.
func GetUserAgent() string {
return fmt.Sprintf("csi-secrets-store/%s", BuildVersion)
return fmt.Sprintf("csi-secrets-store/%s (%s/%s) %s/%s", BuildVersion, runtime.GOOS, runtime.GOARCH, Vcs, BuildDate)
}