Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2022-07-05 23:55:47 +0300
committerJohn Cai <jcai@gitlab.com>2022-07-05 23:55:47 +0300
commit55a7384659af83143fb5076cc70c9e6b532562c9 (patch)
treea1387118fdc37b4a930a574cdf4a4ff929058800
parentbfd3175bf92587f21d17e2107e1e7e2ee0fa69bc (diff)
parenta5e97fc55aebf67ce14a5da64103b8763abb6f23 (diff)
Merge branch 'issue_4049_edith' into 'master'
git: Add a gitversion label to command related metrics See merge request gitlab-org/gitaly!4460
-rw-r--r--internal/command/command.go34
-rw-r--r--internal/command/command_test.go2
-rw-r--r--internal/command/option.go8
-rw-r--r--internal/git/command_factory.go6
4 files changed, 33 insertions, 17 deletions
diff --git a/internal/command/command.go b/internal/command/command.go
index 5f3f3a8f1..f7c1936c6 100644
--- a/internal/command/command.go
+++ b/internal/command/command.go
@@ -30,49 +30,49 @@ var (
Name: "gitaly_command_cpu_seconds_total",
Help: "Sum of CPU time spent by shelling out",
},
- []string{"grpc_service", "grpc_method", "cmd", "subcmd", "mode"},
+ []string{"grpc_service", "grpc_method", "cmd", "subcmd", "mode", "git_version"},
)
realSecondsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gitaly_command_real_seconds_total",
Help: "Sum of real time spent by shelling out",
},
- []string{"grpc_service", "grpc_method", "cmd", "subcmd"},
+ []string{"grpc_service", "grpc_method", "cmd", "subcmd", "git_version"},
)
minorPageFaultsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gitaly_command_minor_page_faults_total",
Help: "Sum of minor page faults performed while shelling out",
},
- []string{"grpc_service", "grpc_method", "cmd", "subcmd"},
+ []string{"grpc_service", "grpc_method", "cmd", "subcmd", "git_version"},
)
majorPageFaultsTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gitaly_command_major_page_faults_total",
Help: "Sum of major page faults performed while shelling out",
},
- []string{"grpc_service", "grpc_method", "cmd", "subcmd"},
+ []string{"grpc_service", "grpc_method", "cmd", "subcmd", "git_version"},
)
signalsReceivedTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gitaly_command_signals_received_total",
Help: "Sum of signals received while shelling out",
},
- []string{"grpc_service", "grpc_method", "cmd", "subcmd"},
+ []string{"grpc_service", "grpc_method", "cmd", "subcmd", "git_version"},
)
contextSwitchesTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gitaly_command_context_switches_total",
Help: "Sum of context switches performed while shelling out",
},
- []string{"grpc_service", "grpc_method", "cmd", "subcmd", "ctxswitchtype"},
+ []string{"grpc_service", "grpc_method", "cmd", "subcmd", "ctxswitchtype", "git_version"},
)
spawnTokenAcquiringSeconds = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "gitaly_command_spawn_token_acquiring_seconds_total",
Help: "Sum of time spent waiting for a spawn token",
},
- []string{"grpc_service", "grpc_method", "cmd"},
+ []string{"grpc_service", "grpc_method", "cmd", "git_version"},
)
// exportedEnvVars contains a list of environment variables
@@ -146,6 +146,7 @@ type Command struct {
metricsCmd string
metricsSubCmd string
cgroupPath string
+ cmdGitVersion string
}
// New creates a Command from an exec.Cmd. On success, the Command contains a running subprocess.
@@ -178,7 +179,7 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
service, method := methodFromContext(ctx)
cmdName := path.Base(cmd.Path)
spawnTokenAcquiringSeconds.
- WithLabelValues(service, method, cmdName).
+ WithLabelValues(service, method, cmdName, cfg.gitVersion).
Add(getSpawnTokenAcquiringSeconds(spawnStartTime))
defer putToken()
@@ -200,6 +201,7 @@ func New(ctx context.Context, cmd *exec.Cmd, opts ...Option) (*Command, error) {
finalizer: cfg.finalizer,
metricsCmd: cfg.commandName,
metricsSubCmd: cfg.subcommandName,
+ cmdGitVersion: cfg.gitVersion,
}
// Export allowed environment variables as set in the Gitaly process.
@@ -421,15 +423,15 @@ func (c *Command) logProcessComplete() {
if c.metricsCmd != "" {
cmdName = c.metricsCmd
}
- cpuSecondsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "system").Add(systemTime.Seconds())
- cpuSecondsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "user").Add(userTime.Seconds())
- realSecondsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd).Add(realTime.Seconds())
+ cpuSecondsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "system", c.cmdGitVersion).Add(systemTime.Seconds())
+ cpuSecondsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "user", c.cmdGitVersion).Add(userTime.Seconds())
+ realSecondsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, c.cmdGitVersion).Add(realTime.Seconds())
if ok {
- minorPageFaultsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd).Add(float64(rusage.Minflt))
- majorPageFaultsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd).Add(float64(rusage.Majflt))
- signalsReceivedTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd).Add(float64(rusage.Nsignals))
- contextSwitchesTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "voluntary").Add(float64(rusage.Nvcsw))
- contextSwitchesTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "nonvoluntary").Add(float64(rusage.Nivcsw))
+ minorPageFaultsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, c.cmdGitVersion).Add(float64(rusage.Minflt))
+ majorPageFaultsTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, c.cmdGitVersion).Add(float64(rusage.Majflt))
+ signalsReceivedTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, c.cmdGitVersion).Add(float64(rusage.Nsignals))
+ contextSwitchesTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "voluntary", c.cmdGitVersion).Add(float64(rusage.Nvcsw))
+ contextSwitchesTotal.WithLabelValues(service, method, cmdName, c.metricsSubCmd, "nonvoluntary", c.cmdGitVersion).Add(float64(rusage.Nivcsw))
}
c.span.LogKV(
diff --git a/internal/command/command_test.go b/internal/command/command_test.go
index 1f6eae3b0..4e2f80248 100644
--- a/internal/command/command_test.go
+++ b/internal/command/command_test.go
@@ -448,7 +448,7 @@ func TestNew_commandSpawnTokenMetrics(t *testing.T) {
expectedMetrics := `# HELP gitaly_command_spawn_token_acquiring_seconds_total Sum of time spent waiting for a spawn token
# TYPE gitaly_command_spawn_token_acquiring_seconds_total counter
-gitaly_command_spawn_token_acquiring_seconds_total{cmd="echo",grpc_method="TestRPC",grpc_service="test.Service"} 1
+gitaly_command_spawn_token_acquiring_seconds_total{cmd="echo",git_version="",grpc_method="TestRPC",grpc_service="test.Service"} 1
`
require.NoError(
t,
diff --git a/internal/command/option.go b/internal/command/option.go
index 08acf0f33..d5ec59635 100644
--- a/internal/command/option.go
+++ b/internal/command/option.go
@@ -16,6 +16,7 @@ type config struct {
commandName string
subcommandName string
+ gitVersion string
cgroupsManager CgroupsManager
cgroupsRepo repository.GitRepo
@@ -70,6 +71,13 @@ func WithCommandName(commandName, subcommandName string) Option {
}
}
+// WithCommandGitVersion overrides the "git_version" label used in metrics.
+func WithCommandGitVersion(gitCmdVersion string) Option {
+ return func(cfg *config) {
+ cfg.gitVersion = gitCmdVersion
+ }
+}
+
// CgroupsManager is a subset of the `cgroups.Manager` interface. We need to replicate it here to
// avoid a cyclic dependency between both packages.
type CgroupsManager interface {
diff --git a/internal/git/command_factory.go b/internal/git/command_factory.go
index 86918985f..b9046b5d4 100644
--- a/internal/git/command_factory.go
+++ b/internal/git/command_factory.go
@@ -396,11 +396,17 @@ func (cf *ExecCommandFactory) newCommand(ctx context.Context, repo repository.Gi
execCommand := exec.Command(execEnv.BinaryPath, args...)
execCommand.Dir = dir
+ cmdGitVersion, err := cf.GitVersion(ctx)
+ if err != nil {
+ return nil, fmt.Errorf("getting Git version: %w", err)
+ }
+
command, err := command.New(ctx, execCommand, append(
config.commandOpts,
command.WithEnvironment(env),
command.WithCommandName("git", sc.Subcommand()),
command.WithCgroup(cf.cgroupsManager, repo),
+ command.WithCommandGitVersion(cmdGitVersion.String()),
)...)
if err != nil {
return nil, err