github.phpd.cn/cilium/cilium@v1.6.12/test/helpers/logutils/utils_test.go (about)

     1  // Copyright 2019 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package logutils
    16  
    17  import (
    18  	"testing"
    19  
    20  	. "gopkg.in/check.v1"
    21  )
    22  
    23  // Hook up gocheck into the "go test" runner.
    24  type LogutilsTestSuite struct{}
    25  
    26  var _ = Suite(&LogutilsTestSuite{})
    27  
    28  func Test(t *testing.T) {
    29  	TestingT(t)
    30  }
    31  
    32  func (s *LogutilsTestSuite) TestLogErrorsSummary(c *C) {
    33  	log := `Mar 05 07:51:17 runtime cilium-agent[11336]: level=debug msg="Process exited" cmd="cilium-health [-d]" exitCode="<nil>" subsys=launcher
    34  Mar 05 07:51:17 runtime cilium-agent[11336]: level=warning msg="Error while running monitor" error="Unable to read stdout from monitor: EOF" subsys=monitor-launcher
    35  Mar 05 07:51:17 runtime cilium-agent[11336]: level=debug msg="Sleeping with exponential backoff" attempt=1 fields.time=2s name=75419b5f-3f1b-11e9-9375-080027b5ed00 subsys=backoff
    36  Mar 05 07:51:17 runtime cilium-agent[11336]: level=error msg="xDS stream context canceled" error="context canceled" subsys=xds xdsStreamID=3
    37  Mar 05 07:51:17 runtime cilium-agent[11336]: level=info msg="Envoy: Closing access log connection" subsys=envoy-manager
    38  Mar 05 07:51:17 runtime cilium-agent[11336]: level=debug msg="xDS stream closed" subsys=xds xdsStreamID=3
    39  Mar 05 07:51:17 runtime cilium-agent[11336]: level=error msg="error while receiving request from xDS stream" error="rpc error: code = Canceled desc = context canceled" subsys=xds xdsStreamID=2
    40  Mar 05 07:51:17 runtime cilium-agent[11336]: level=error msg="xDS stream context canceled" error="context canceled" subsys=xds xdsStreamID=1
    41  Mar 05 07:51:17 runtime cilium-agent[11336]: level=error msg="xDS stream context canceled" error="context canceled" subsys=xds xdsStreamID=1
    42  Mar 05 07:51:17 runtime cilium-agent[11336]: level=error msg="error while receiving request from xDS stream" error="rpc error: code = Canceled desc = context canceled" subsys=xds xdsStreamID=1
    43  2019-03-11T11:42:29.197427096Z level=error msg=k8sError error="github.com/cilium/cilium/daemon/k8s_watcher.go:847: expected type *v1.Node, but watch event object had type *v1.Namespace" subsys=k8s`
    44  
    45  	output := LogErrorsSummary(log)
    46  
    47  	expected := `Number of "context deadline exceeded" in logs: 0
    48  ⚠️  Number of "level=error" in logs: 6
    49  Number of "level=warning" in logs: 1
    50  Number of "Cilium API handler panicked" in logs: 0
    51  Number of "Goroutine took lock for more than" in logs: 0
    52  Top 4 errors/warnings:
    53  xDS stream context canceled
    54  error while receiving request from xDS stream
    55  github.com/cilium/cilium/daemon/k8s_watcher.go:847: expected type *v1.Node, but watch event object had type *v1.Namespace
    56  Error while running monitor
    57  `
    58  
    59  	c.Assert(output, Equals, expected)
    60  
    61  	output = LogErrorsSummary("")
    62  	expected = `Number of "context deadline exceeded" in logs: 0
    63  Number of "level=error" in logs: 0
    64  Number of "level=warning" in logs: 0
    65  Number of "Cilium API handler panicked" in logs: 0
    66  Number of "Goroutine took lock for more than" in logs: 0
    67  No errors/warnings found in logs
    68  `
    69  
    70  	c.Assert(output, Equals, expected)
    71  }