Content-Length: 598865 | pFad | http://github.com/GoogleCloudPlatform/sapagent/commit/8cf166355d6ea2b4840712f3938a14e35710d2ae

0F Added Usage metrics to support bundle tool. · GoogleCloudPlatform/sapagent@8cf1663 · GitHub
Skip to content

Commit 8cf1663

Browse files
Neejor Chakmacopybara-github
Neejor Chakma
authored andcommitted
Added Usage metrics to support bundle tool.
PiperOrigin-RevId: 763637841
1 parent 8e5630b commit 8cf1663

File tree

4 files changed

+39
-11
lines changed

4 files changed

+39
-11
lines changed

internal/onetime/supportbundle/supportbundle.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (*SupportBundle) Synopsis() string {
360360
// Usage implements the subcommand interface for support bundle report collection for support team.
361361
func (*SupportBundle) Usage() string {
362362
return `Usage: supportbundle [-sid=<SAP System Identifier>] [-instance-numbers=<Instance numbers>]
363-
[-hostname=<Hostname>] [agent-logs-only=true|false] [-metrics] [-metrics]
363+
[-hostname=<Hostname>] [agent-logs-only=true|false] [-pacemaker-diagnosis=true|false] [-metrics=true|false]
364364
[-timestamp=<YYYY-MM-DD HH:MM:SS>] [-before-duration=<duration in seconds>] [-after-duration=<duration in seconds>]
365365
[-h] [-loglevel=<debug|info|warn|error>]
366366
[-result-bucket=<name of the result bucket where bundle zip is uploaded>] [-log-path=<log-path>]
@@ -433,6 +433,7 @@ func (s *SupportBundle) supportBundleHandler(ctx context.Context, destFilePathPr
433433
s.oteLogger.LogErrorToFileAndConsole(ctx, "Invalid params for collecting support bundle Report for Agent for SAP", errors.New(errMessage))
434434
return fmt.Sprintf("Invalid params for collecting support bundle Report for Agent for SAP: %s", errMessage), subcommands.ExitUsageError
435435
}
436+
s.oteLogger.LogUsageAction(usagemetrics.SupportBundle)
436437
s.Sid = strings.ToUpper(s.Sid)
437438
bundlename := fmt.Sprintf("supportbundle-%s-%s", s.Hostname, strings.Replace(time.Now().Format(time.RFC3339), ":", "-", -1))
438439
destFilesPath := fmt.Sprintf("%s%s", destFilePathPrefix, bundlename)
@@ -535,10 +536,12 @@ func (s *SupportBundle) supportBundleHandler(ctx context.Context, destFilePathPr
535536
}
536537

537538
if s.ResultBucket != "" {
539+
s.oteLogger.LogUsageAction(usagemetrics.SupportBundleUploadStarted)
538540
if err := s.uploadZip(ctx, zipfile, bundlename, storage.ConnectToBucket, getReadWriter, fs, st.NewClient); err != nil {
539541
errMessage := fmt.Sprintf("Error while uploading zip file %s to bucket %s", destFilePathPrefix+".zip", s.ResultBucket)
540542
s.oteLogger.LogMessageToConsole(fmt.Sprintf(errMessage, " Error: ", err))
541543
failureMsgs = append(failureMsgs, errMessage)
544+
s.oteLogger.LogUsageError(usagemetrics.SupportBundleUploadFailure)
542545
} else {
543546
msg := fmt.Sprintf("Bundle uploaded to bucket %s, path: %s", s.ResultBucket, fmt.Sprintf("gs://%s/%s/%s.zip", s.ResultBucket, s.Name(), bundlename))
544547
successMsgs = append(successMsgs, msg)
@@ -549,6 +552,8 @@ func (s *SupportBundle) supportBundleHandler(ctx context.Context, destFilePathPr
549552
failureMsgs = append(failureMsgs, errMessage)
550553
}
551554
}
555+
} else {
556+
s.oteLogger.LogUsageAction(usagemetrics.SupportBundleLocalCollection)
552557
}
553558

554559
// Rotate out old support bundles so we don't fill the file system.
@@ -1437,7 +1442,7 @@ func (s *SupportBundle) getMetricsClients(ctx context.Context) error {
14371442

14381443
qc, err := s.createQueryClient(ctx)
14391444
if err != nil {
1440-
usagemetrics.Error(usagemetrics.QueryClientCreateFailure)
1445+
s.oteLogger.LogUsageError(usagemetrics.QueryClientCreateFailure)
14411446
return err
14421447
}
14431448
cmr := &cloudmetricreader.CloudMetricReader{
@@ -1447,7 +1452,7 @@ func (s *SupportBundle) getMetricsClients(ctx context.Context) error {
14471452

14481453
mmc, err := s.createMetricClient(ctx)
14491454
if err != nil {
1450-
usagemetrics.Error(usagemetrics.MetricClientCreateFailure)
1455+
s.oteLogger.LogUsageError(usagemetrics.MetricClientCreateFailure)
14511456
return err
14521457
}
14531458

@@ -1578,21 +1583,21 @@ func (s *SupportBundle) fetchLabelDescriptors(ctx context.Context, cp *ipb.Cloud
15781583
}
15791584

15801585
// newQueryClient abstracts the creation of a new Cloud Monitoring query client for testing purposes.
1581-
func newQueryClient(ctx context.Context) (cloudmonitoring.TimeSeriesQuerier, error) {
1586+
func (s *SupportBundle) newQueryClient(ctx context.Context) (cloudmonitoring.TimeSeriesQuerier, error) {
15821587
mqc, err := monitoring.NewQueryClient(ctx)
15831588
if err != nil {
1584-
usagemetrics.Error(usagemetrics.QueryClientCreateFailure)
1589+
s.oteLogger.LogUsageError(usagemetrics.QueryClientCreateFailure)
15851590
return nil, fmt.Errorf("failed to create Cloud Monitoring query client: %v", err)
15861591
}
15871592

15881593
return &cloudmetricreader.QueryClient{Client: mqc}, nil
15891594
}
15901595

15911596
// newMetricClient abstracts the creation of a new Cloud Monitoring metric client for testing purposes.
1592-
func newMetricClient(ctx context.Context) (cloudmonitoring.TimeSeriesDescriptorQuerier, error) {
1597+
func (s *SupportBundle) newMetricClient(ctx context.Context) (cloudmonitoring.TimeSeriesDescriptorQuerier, error) {
15931598
mmc, err := monitoring.NewMetricClient(ctx)
15941599
if err != nil {
1595-
usagemetrics.Error(usagemetrics.MetricClientCreateFailure)
1600+
s.oteLogger.LogUsageError(usagemetrics.MetricClientCreateFailure)
15961601
return nil, fmt.Errorf("failed to create Cloud Monitoring metric client: %v", err)
15971602
}
15981603

@@ -1627,8 +1632,8 @@ func (s *SupportBundle) validateParams() []string {
16271632
s.rest = &rest.Rest{}
16281633
s.rest.NewRest()
16291634

1630-
s.createQueryClient = newQueryClient
1631-
s.createMetricClient = newMetricClient
1635+
s.createQueryClient = s.newQueryClient
1636+
s.createMetricClient = s.newMetricClient
16321637

16331638
return errs
16341639
}

internal/onetime/supportbundle/supportbundle_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2939,6 +2939,7 @@ func TestGetProcessMetricsClients(t *testing.T) {
29392939
ctx := context.Background()
29402940
for _, tc := range tests {
29412941
t.Run(tc.name, func(t *testing.T) {
2942+
tc.s.oteLogger = defaultOTELogger
29422943
err := tc.s.getMetricsClients(ctx)
29432944
if !cmp.Equal(err, tc.wantErr, cmpopts.EquateErrors()) {
29442945
t.Errorf("getProcessMetricsClients() returned an unexpected error: %v", err)
@@ -3580,7 +3581,10 @@ func TestNewQueryClient(t *testing.T) {
35803581
ctx := context.Background()
35813582
for _, tc := range tests {
35823583
t.Run(tc.name, func(t *testing.T) {
3583-
_, err := newQueryClient(ctx)
3584+
var s = &SupportBundle{
3585+
oteLogger: defaultOTELogger,
3586+
}
3587+
_, err := s.newQueryClient(ctx)
35843588
if diff := cmp.Diff(err, tc.wantErr, cmpopts.EquateErrors()); diff != "" {
35853589
t.Errorf("NewQueryClient() returned an unexpected error: %v", diff)
35863590
}
@@ -3602,7 +3606,10 @@ func TestNewMetricClient(t *testing.T) {
36023606
ctx := context.Background()
36033607
for _, tc := range tests {
36043608
t.Run(tc.name, func(t *testing.T) {
3605-
_, err := newMetricClient(ctx)
3609+
s := &SupportBundle{
3610+
oteLogger: defaultOTELogger,
3611+
}
3612+
_, err := s.newMetricClient(ctx)
36063613
if diff := cmp.Diff(err, tc.wantErr, cmpopts.EquateErrors()); diff != "" {
36073614
t.Errorf("NewMetricClient() returned an unexpected error: %v", diff)
36083615
}

internal/usagemetrics/usagemetrics.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ const (
124124
HANAChangeDiskTypeSnapshotFailure = 83 // HANAChangeDiskTypeSnapshotFailure
125125
HANAChangeDiskTypeRestoreFailure = 84 // HANAChangeDiskTypeRestoreFailure
126126
RemoteValidationOTEFailure = 85 // RemoteValidationFailure
127+
SupportBundleUploadFailure = 86 // SupportBundleUploadFailure
127128
)
128129

129130
// Agent wide action mappings - Only append the action codes at the end of the list.
@@ -219,6 +220,9 @@ const (
219220
HANAChangeDiskTypeFinished = 86 // HANAChangeDiskTypeFinished
220221
RemoteValidationOTEStarted = 87 // RemoteValidationOTEStarted
221222
RemoteValidationOTEFinished = 88 // RemoteValidationOTEFinished
223+
SupportBundle = 89 // SupportBundle
224+
SupportBundleUploadStarted = 90 // SupportBundleUploadStarted
225+
SupportBundleLocalCollection = 91 // SupportBundleLocalCollection
222226
)
223227

224228
// projectNumbers contains known project numbers for test instances.

internal/usagemetrics/usagemetrics_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ func TestErrorConstants(t *testing.T) {
277277
if RemoteValidationOTEFailure != 85 {
278278
t.Errorf("RemoteValidationOTEFailure = %v, want 85", RemoteValidationOTEFailure)
279279
}
280+
if SupportBundleUploadFailure != 86 {
281+
t.Errorf("PacemakerDiagnosisFailure = %v, want 83", SupportBundleUploadFailure)
282+
}
280283
}
281284

282285
func TestActionConstants(t *testing.T) {
@@ -547,4 +550,13 @@ func TestActionConstants(t *testing.T) {
547550
if RemoteValidationOTEFinished != 88 {
548551
t.Errorf("RemoteValidationOTEFinished = %v, want 88", RemoteValidationOTEFinished)
549552
}
553+
if SupportBundle != 89 {
554+
t.Errorf("SupportBundle = %v, want 85", SupportBundle)
555+
}
556+
if SupportBundleUploadStarted != 90 {
557+
t.Errorf("SupportBundleUploadStarted = %v, want 87", SupportBundleUploadStarted)
558+
}
559+
if SupportBundleLocalCollection != 91 {
560+
t.Errorf("SupportBundleLocalCollection = %v, want 88", SupportBundleLocalCollection)
561+
}
550562
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/GoogleCloudPlatform/sapagent/commit/8cf166355d6ea2b4840712f3938a14e35710d2ae

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy