forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log,importccl,backupccl: add event logs for import and restore jobs
This change adds a new `CommonJobEventDetails` and two implementations of the interface in `Import` and `Restore`, to structure the events emitted during different phases of the job execution. Both Import/Restore will emit logs at the following stages: - When the job has completed preparing and is beginning execution. - When the job has succeeded. - When the job has started reverting. - When the job has finished reverting and is in a terminal failed state. Release note (sql change): IMPORT and RESTORE now emit structured events to the OPS channel. Refer to the generated documentation for details.
- Loading branch information
1 parent
46a8edd
commit afa9b6d
Showing
22 changed files
with
1,651 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package backupccl | ||
|
||
import ( | ||
"encoding/json" | ||
"math" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/testutils" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/cockroach/pkg/util/log/eventpb" | ||
"github.com/cockroachdb/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// CheckEmittedEvents is a helper method used by IMPORT and RESTORE tests to | ||
// ensure events are emitted deterministically. | ||
func CheckEmittedEvents( | ||
t *testing.T, | ||
expectedStatus []string, | ||
startTime int64, | ||
jobID int64, | ||
expectedMessage, expectedJobType string, | ||
) { | ||
// Check that the structured event was logged. | ||
testutils.SucceedsSoon(t, func() error { | ||
log.Flush() | ||
entries, err := log.FetchEntriesFromFiles(startTime, | ||
math.MaxInt64, 10000, cmLogRe, log.WithMarkedSensitiveData) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
foundEntry := false | ||
for i, e := range entries { | ||
if !strings.Contains(e.Message, expectedMessage) { | ||
continue | ||
} | ||
foundEntry = true | ||
// TODO(knz): Remove this when crdb-v2 becomes the new format. | ||
e.Message = strings.TrimPrefix(e.Message, "Structured entry:") | ||
// crdb-v2 starts json with an equal sign. | ||
e.Message = strings.TrimPrefix(e.Message, "=") | ||
jsonPayload := []byte(e.Message) | ||
var ev eventpb.CommonJobEventDetails | ||
if err := json.Unmarshal(jsonPayload, &ev); err != nil { | ||
t.Errorf("unmarshalling %q: %v", e.Message, err) | ||
} | ||
require.Equal(t, expectedJobType, ev.JobType) | ||
require.Equal(t, jobID, ev.JobID) | ||
require.Equal(t, expectedStatus[i], ev.Status) | ||
} | ||
if !foundEntry { | ||
return errors.New("structured entry for import not found in log") | ||
} | ||
return nil | ||
}) | ||
} | ||
|
||
var cmLogRe = regexp.MustCompile(`event_log\.go`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.