Fix ES cluster logging test

This commit is contained in:
Mikhail Vyatskov 2017-03-14 17:48:58 -07:00
parent a8d8542fc7
commit 720b4c5c99
2 changed files with 18 additions and 7 deletions

View File

@ -166,15 +166,15 @@ func (logsProvider *esLogsProvider) ReadEntries(pod *loggingPod) []*logEntry {
return nil return nil
} }
query := fmt.Sprintf("kubernetes.pod_name:%s AND kubernetes.namespace_name:%s", pod.Name, f.Namespace.Name)
framework.Logf("Sending a search request to Elasticsearch with the following query: %s", query)
// Ask Elasticsearch to return all the log lines that were tagged with the // Ask Elasticsearch to return all the log lines that were tagged with the
// pod name. Ask for ten times as many log lines because duplication is possible. // pod name. Ask for ten times as many log lines because duplication is possible.
body, err := proxyRequest.Namespace(api.NamespaceSystem). body, err := proxyRequest.Namespace(api.NamespaceSystem).
Name("elasticsearch-logging"). Name("elasticsearch-logging").
Suffix("_search"). Suffix("_search").
// TODO: Change filter to only match records from current test run Param("q", query).
// after fluent-plugin-kubernetes_metadata_filter is enabled
// and optimize current query
Param("q", fmt.Sprintf("tag:*%s*", pod.Name)).
// Ask for more in case we included some unrelated records in our query // Ask for more in case we included some unrelated records in our query
Param("size", strconv.Itoa(pod.ExpectedLinesNumber*10)). Param("size", strconv.Itoa(pod.ExpectedLinesNumber*10)).
DoRaw() DoRaw()

View File

@ -18,8 +18,8 @@ package e2e
import ( import (
"fmt" "fmt"
"regexp"
"strconv" "strconv"
"strings"
"time" "time"
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
@ -42,6 +42,11 @@ const (
loggingContainerMemoryRequest = 10 * 1024 * 1024 loggingContainerMemoryRequest = 10 * 1024 * 1024
) )
var (
// Regexp, matching the contents of log entries, parsed or not
logEntryMessageRegex = regexp.MustCompile("(?:I\\d+ \\d+:\\d+:\\d+.\\d+ \\d+ logs_generator.go:67] )?(\\d+) .*")
)
// Type to track the progress of logs generating pod // Type to track the progress of logs generating pod
type loggingPod struct { type loggingPod struct {
// Name of the pod // Name of the pod
@ -77,8 +82,12 @@ type loggingTestConfig struct {
} }
func (entry *logEntry) getLogEntryNumber() (int, bool) { func (entry *logEntry) getLogEntryNumber() (int, bool) {
chunks := strings.Split(entry.Payload, " ") submatch := logEntryMessageRegex.FindStringSubmatch(entry.Payload)
lineNumber, err := strconv.Atoi(strings.TrimSpace(chunks[0])) if submatch == nil || len(submatch) < 2 {
return 0, false
}
lineNumber, err := strconv.Atoi(submatch[1])
return lineNumber, err == nil return lineNumber, err == nil
} }
@ -212,6 +221,8 @@ func pullMissingLogsCount(logsProvider logsProvider, pod *loggingPod) int {
func getMissingLinesCount(logsProvider logsProvider, pod *loggingPod) (int, error) { func getMissingLinesCount(logsProvider logsProvider, pod *loggingPod) (int, error) {
entries := logsProvider.ReadEntries(pod) entries := logsProvider.ReadEntries(pod)
framework.Logf("Got %d entries from provider", len(entries))
for _, entry := range entries { for _, entry := range entries {
lineNumber, ok := entry.getLogEntryNumber() lineNumber, ok := entry.getLogEntryNumber()
if !ok { if !ok {