Skip to content

Commit

Permalink
Update Go to v1.22.2
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkondr committed Apr 16, 2024
1 parent 734333c commit 912475e
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 386 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ help: ## Display this help message
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'

init: ## Install development tools
rm -rf bin
cd tools && go generate -x -tags=tools

build: ## Compile using plain go build
Expand Down Expand Up @@ -44,4 +45,4 @@ test-crosscover: ## Run tests and collect cross-package coverage informat

run: ## Run telemetry-agent with race detector
go run -race cmd/telemetry-agent/main.go \
--verbose --dev-mode
--log.verbose --log.dev-mode
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/percona/telemetry-agent

go 1.21.7
go 1.22.2

require (
github.com/alecthomas/kong v0.9.0
Expand Down Expand Up @@ -38,4 +38,4 @@ require (
)

// indirect dependency replaced because of security vulnerability
replace goauthentik.io => goauthentik.io v0.0.0-20230302191751-63cfbb721cd7 //indirect
//replace goauthentik.io => goauthentik.io v0.0.0-20230302191751-63cfbb721cd7 //indirect
2 changes: 1 addition & 1 deletion metrics/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func checkDirectoryContentCount(t *testing.T, tmpDir string, wantCount int) {
t.Helper()
files, err := os.ReadDir(tmpDir)
require.NoError(t, err)
require.Equal(t, len(files), wantCount)
require.Len(t, files, wantCount)
}

func checkHistoryFileContent(t *testing.T, tmpDir, historyFile string, req *platformReporter.ReportRequest) {
Expand Down
4 changes: 2 additions & 2 deletions metrics/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// Percona Platform telemetry request into it. Content is written using JSON format.
func WriteMetricsToHistory(historyFile string, platformReport *platformReporter.ReportRequest) error {
l := zap.L().Sugar()
if platformReport == nil || len(platformReport.Reports) == 0 {
if platformReport == nil || len(platformReport.GetReports()) == 0 {
l.Errorw("attempt to write invalid Percona Platform report into history file",
zap.Any("report", platformReport))
return errors.New("invalid Percona Platform report, ReportRequest.Reports is empty")
Expand Down Expand Up @@ -121,7 +121,7 @@ func validateDirectory(dirPath string) error {
return err
}
if !info.IsDir() {
return fmt.Errorf("provided path is not a directory")
return errors.New("provided path is not a directory")
}
return nil
}
28 changes: 13 additions & 15 deletions metrics/history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,26 @@ func TestWriteMetricsToHistory(t *testing.T) {
}{
{
name: "non_existing_directory",
setupTestData: func(t *testing.T, tmpDir, token string, currTime time.Time) {
setupTestData: func(t *testing.T, tmpDir, _ string, _ time.Time) {
t.Helper()
// make directory absent
_ = os.RemoveAll(tmpDir)
},
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, req *platformReporter.ReportRequest) {
postCheckTestData: func(t *testing.T, tmpDir, _, _ string, _ time.Time, _ *platformReporter.ReportRequest) {
t.Helper()
// directory shall not be created
_, err := os.Stat(tmpDir)
require.Error(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
},
request: &platformReporter.ReportRequest{},
wantErr: true,
},
{
name: "empty_request_empty_directory",
setupTestData: func(t *testing.T, tmpDir, token string, currTime time.Time) {
setupTestData: func(t *testing.T, _, _ string, _ time.Time) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, req *platformReporter.ReportRequest) {
postCheckTestData: func(t *testing.T, tmpDir, _, _ string, _ time.Time, _ *platformReporter.ReportRequest) {
t.Helper()
// no new files shall be created
checkDirectoryContentCount(t, tmpDir, 0)
Expand All @@ -76,7 +76,7 @@ func TestWriteMetricsToHistory(t *testing.T) {
fmt.Sprintf("%d-%s.json", (currTime.Add(-10*time.Minute)).Unix(), token),
fmt.Sprintf("%d-%s.json", (currTime.Add(-20*time.Minute)).Unix(), token))
},
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, req *platformReporter.ReportRequest) {
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, _ *platformReporter.ReportRequest) {
t.Helper()
checkDirectoryContentCount(t, tmpDir, 3)

Expand All @@ -93,10 +93,10 @@ func TestWriteMetricsToHistory(t *testing.T) {
},
{
name: "no_request_reports_empty_directory",
setupTestData: func(t *testing.T, tmpDir, token string, currTime time.Time) {
setupTestData: func(t *testing.T, _, _ string, _ time.Time) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, req *platformReporter.ReportRequest) {
postCheckTestData: func(t *testing.T, tmpDir, _, _ string, _ time.Time, _ *platformReporter.ReportRequest) {
t.Helper()
// no new files shall be created
checkDirectoryContentCount(t, tmpDir, 0)
Expand All @@ -113,7 +113,7 @@ func TestWriteMetricsToHistory(t *testing.T) {
fmt.Sprintf("%d-%s.json", (currTime.Add(-10*time.Minute)).Unix(), token),
fmt.Sprintf("%d-%s.json", (currTime.Add(-20*time.Minute)).Unix(), token))
},
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, req *platformReporter.ReportRequest) {
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, _ *platformReporter.ReportRequest) {
t.Helper()
checkDirectoryContentCount(t, tmpDir, 3)

Expand All @@ -130,10 +130,10 @@ func TestWriteMetricsToHistory(t *testing.T) {
},
{
name: "single_report_empty_directory",
setupTestData: func(t *testing.T, tmpDir, token string, currTime time.Time) {
setupTestData: func(t *testing.T, _, _ string, _ time.Time) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, historyFile, token string, currTime time.Time, req *platformReporter.ReportRequest) {
postCheckTestData: func(t *testing.T, tmpDir, historyFile, _ string, _ time.Time, req *platformReporter.ReportRequest) {
t.Helper()
// only one file shall be created
checkDirectoryContentCount(t, tmpDir, 1)
Expand Down Expand Up @@ -194,7 +194,6 @@ func TestWriteMetricsToHistory(t *testing.T) {
}

for _, tt := range testCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -276,7 +275,7 @@ func TestCleanupMetricsHistory(t *testing.T) {
},
{
name: "empty_directory",
setupTestData: func(t *testing.T, tmpDir string) {
setupTestData: func(t *testing.T, _ string) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir string) {
Expand All @@ -297,15 +296,14 @@ func TestCleanupMetricsHistory(t *testing.T) {
t.Helper()
// directory shall not be created
_, err := os.Stat(tmpDir)
require.Error(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
},
keepInterval: 3600,
wantErr: true,
},
}

for _, tt := range testCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
13 changes: 5 additions & 8 deletions metrics/host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestGetInstanceID(t *testing.T) {
}{
{
name: "non_existing_directory",
setupTestData: func(t *testing.T, tmpDir, instanceFile, instanceID string) {
setupTestData: func(t *testing.T, _, _, _ string) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, instanceFile, wantInstanceID string) {
Expand All @@ -50,7 +50,7 @@ func TestGetInstanceID(t *testing.T) {
},
{
name: "non_existing_file",
setupTestData: func(t *testing.T, tmpDir, instanceFile, instanceID string) {
setupTestData: func(t *testing.T, _, _, _ string) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, instanceFile, wantInstanceID string) {
Expand All @@ -63,7 +63,7 @@ func TestGetInstanceID(t *testing.T) {
},
{
name: "empty_file",
setupTestData: func(t *testing.T, tmpDir, instanceFile, instanceID string) {
setupTestData: func(t *testing.T, tmpDir, instanceFile, _ string) {
t.Helper()
// create empty file
_, err := os.Create(filepath.Clean(filepath.Join(tmpDir, instanceFile)))
Expand Down Expand Up @@ -173,7 +173,6 @@ func TestGetInstanceID(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -218,7 +217,7 @@ func TestReadOSReleaseFile(t *testing.T) {
}{
{
name: "file_absent",
setupTestData: func(t *testing.T, tmpDir, releaseFile string) {
setupTestData: func(t *testing.T, _, _ string) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, releaseFile string) {
Expand Down Expand Up @@ -264,7 +263,6 @@ ORACLE_SUPPORT_PRODUCT_VERSION=9.2
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -294,7 +292,7 @@ func TestReadSystemReleaseFile(t *testing.T) {
}{
{
name: "file_absent",
setupTestData: func(t *testing.T, tmpDir, releaseFile string) {
setupTestData: func(t *testing.T, _, _ string) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, releaseFile string) {
Expand Down Expand Up @@ -337,7 +335,6 @@ func TestReadSystemReleaseFile(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
11 changes: 5 additions & 6 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ func TestParseMetricsFile(t *testing.T) {
}{
{
name: "non_existing_directory",
setupTestData: func(t *testing.T, tmpDir, metricsFile string) {
setupTestData: func(t *testing.T, tmpDir, _ string) {
t.Helper()
// make directory absent
_ = os.RemoveAll(tmpDir)
},
postCheckTestData: func(t *testing.T, tmpDir, metricsFile string, parsedMetrics *File) {
postCheckTestData: func(t *testing.T, tmpDir, _ string, parsedMetrics *File) {
t.Helper()
// directory shall not be created
_, err := os.Stat(tmpDir)
require.Error(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
require.Nil(t, parsedMetrics)
},
wantErr: true,
},
{
name: "empty_directory",
setupTestData: func(t *testing.T, tmpDir, metricsFile string) {
setupTestData: func(t *testing.T, _, _ string) {
t.Helper()
},
postCheckTestData: func(t *testing.T, tmpDir, metricsFile string, parsedMetrics *File) {
Expand All @@ -50,7 +50,7 @@ func TestParseMetricsFile(t *testing.T) {

// file shall not be created
_, err = os.Stat(filepath.Clean(filepath.Join(tmpDir, metricsFile)))
require.Error(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
require.Nil(t, parsedMetrics)
},
wantErr: true,
Expand Down Expand Up @@ -158,7 +158,6 @@ func TestParseMetricsFile(t *testing.T) {
}

for _, tt := range testCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down
11 changes: 8 additions & 3 deletions metrics/package_debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"go.uber.org/zap"
)

var (
errUnexpectedRepoLine = errors.New("unexpected package repository line")
errUnexpectedConfiguredRepoLine = errors.New("unexpected configured package repository line")
)

func queryDebianPackage(ctx context.Context, packageNamePattern string) ([]*Package, error) {
args := []string{"dpkg-query", "-f", "'${db:Status-Abbrev}|${binary:Package}|${source:Version}\n'", "-W", packageNamePattern}
zap.L().Sugar().Debugw("executing command", zap.String("cmd", strings.Join(args, " ")))
Expand All @@ -28,7 +33,7 @@ func queryDebianPackage(ctx context.Context, packageNamePattern string) ([]*Pack

func parseDebianPackageOutput(dpkgOutput []byte, dpkgErr error, isPerconaPackage bool) ([]*Package, error) { //nolint:cyclop
if dpkgErr != nil {
if strings.Contains(string(dpkgOutput), "no packages found matching") {
if strings.Contains(dpkgErr.Error(), "no packages found matching") {
// package is not installed
return nil, errPackageNotFound
}
Expand Down Expand Up @@ -201,7 +206,7 @@ func parseDebianRepositoryOutput(repoOutput []byte, repoErr error, isPerconaPack
if len(tokens) != 3 {
// smth strange
zap.L().Sugar().Warnw("unexpected configured package repository line", zap.String("line", line))
return nil, errors.New("unexpected configured package repository line")
return nil, errUnexpectedConfiguredRepoLine
}
priority := tokens[2]
for scanner.Scan() {
Expand Down Expand Up @@ -232,7 +237,7 @@ func parseDebianPackageRepositoryLine(repositoryLine string, isPerconaPackage bo
if len(repoTokens) < 3 {
// this is case with filesystem path or smth strange
zap.L().Sugar().Warnw("unexpected package repository line", zap.String("line", repositoryLine))
return nil, errors.New("unexpected package repository line")
return nil, errUnexpectedRepoLine
}

repoAddr := repoTokens[1]
Expand Down
Loading

0 comments on commit 912475e

Please sign in to comment.