File: module.go

package info (click to toggle)
gitlab-agent 16.1.3-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 6,324 kB
  • sloc: makefile: 175; sh: 52; ruby: 3
file content (38 lines) | stat: -rw-r--r-- 907 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package server

import (
	"context"

	"cloud.google.com/go/profiler"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/internal/module/google_profiler"
	"gitlab.com/gitlab-org/cluster-integration/gitlab-agent/v16/pkg/kascfg"
	"google.golang.org/api/option"
)

type module struct {
	cfg     *kascfg.GoogleProfilerCF
	service string
	version string
}

func (m *module) Run(ctx context.Context) error {
	if !m.cfg.Enabled {
		return nil
	}
	config := profiler.Config{
		Service:        m.service,
		ServiceVersion: m.version,
		DebugLogging:   m.cfg.DebugLogging,
		MutexProfiling: true, // like in LabKit
		ProjectID:      m.cfg.ProjectId,
	}
	var opts []option.ClientOption
	if m.cfg.CredentialsFile != "" {
		opts = append(opts, option.WithCredentialsFile(m.cfg.CredentialsFile))
	}
	return profiler.Start(config, opts...)
}

func (m *module) Name() string {
	return google_profiler.ModuleName
}