MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / ParseJSONLogs

Function ParseJSONLogs

tests/utils/logs/logs.go:37–63  ·  view source on GitHub ↗

ParseJSONLogs returns the pod's logs of a given pod name, in the form of a list of JSON entries

(
	ctx context.Context,
	kubeInterface kubernetes.Interface,
	namespace string, podName string,
)

Source from the content-addressed store, hash-verified

35// ParseJSONLogs returns the pod's logs of a given pod name,
36// in the form of a list of JSON entries
37func ParseJSONLogs(
38 ctx context.Context,
39 kubeInterface kubernetes.Interface,
40 namespace string, podName string,
41) ([]map[string]interface{}, error) {
42 // Gather pod logs
43 podLogs, err := pods.Logs(ctx, kubeInterface, namespace, podName)
44 if err != nil {
45 return nil, err
46 }
47
48 // In pod logs, each row is stored as JSON object. Split the JSON objects into JSON array
49 logEntries := strings.Split(podLogs, "\n")
50 parsedLogEntries := make([]map[string]interface{}, len(logEntries))
51 for i, entry := range logEntries {
52 if entry == "" {
53 continue
54 }
55 parsedEntry := make(map[string]interface{})
56 err := json.Unmarshal([]byte(entry), &parsedEntry)
57 if err != nil {
58 return nil, err
59 }
60 parsedLogEntries[i] = parsedEntry
61 }
62 return parsedLogEntries, nil
63}
64
65// HasLogger verifies if a given value exists inside a list of JSON entries
66func HasLogger(logEntries []map[string]interface{}, logger string) bool {

Callers 3

logs_test.goFile · 0.92

Calls 1

LogsFunction · 0.92

Tested by

no test coverage detected