-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18756 from hongkailiu/clLogging
Automatic merge from submit-queue. Log test duration with json format for cluster-loader An example of the log entry: {"marker":"cluster_loader_marker","name":"cluster-loader-test","type":"TestDuration","startTime":"2018-02-26T22:44:56.46700834Z","testDuration":"639.046555ms"} The 3rd party, eg, logstash/fluentd can parse the json output by filtering out the entry by marker. For now, it is hard coded as "cluster_loader_marker".
- Loading branch information
Showing
4 changed files
with
57 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cluster | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
const ( | ||
marker_name string = "cluster_loader_marker" | ||
) | ||
|
||
type Metrics interface { | ||
printLog() error | ||
} | ||
|
||
type BaseMetrics struct { | ||
// To let the 3rd party know that this log entry is important | ||
// TODO set this up by config file | ||
Marker string `json:"marker"` | ||
Name string `json:"name"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type TestDuration struct { | ||
BaseMetrics | ||
StartTime time.Time `json:"startTime"` | ||
TestDuration string `json:"testDuration"` | ||
} | ||
|
||
func (td TestDuration) printLog() error { | ||
b, err := json.Marshal(td) | ||
fmt.Println(string(b)) | ||
return err | ||
} | ||
|
||
func LogMetrics(metrics []Metrics) error { | ||
for _, m := range metrics { | ||
err := m.printLog() | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func NewTestDuration(name string, startTime time.Time, testDuration time.Duration) TestDuration { | ||
return TestDuration{ | ||
BaseMetrics: BaseMetrics{ | ||
Marker: marker_name, | ||
Name: name, | ||
Type: fmt.Sprintf("%T", (*TestDuration)(nil))[1:]}, | ||
StartTime: startTime, | ||
TestDuration: fmt.Sprintf("%s", testDuration.String())} | ||
} |
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