YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/Users/deen/code/yugabyte-db/src/yb/integration-tests/logging-test.cc
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
//
18
// The following only applies to changes made to this file as part of YugaByte development.
19
//
20
// Portions Copyright (c) YugaByte, Inc.
21
//
22
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
23
// in compliance with the License.  You may obtain a copy of the License at
24
//
25
// http://www.apache.org/licenses/LICENSE-2.0
26
//
27
// Unless required by applicable law or agreed to in writing, software distributed under the License
28
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
29
// or implied.  See the License for the specific language governing permissions and limitations
30
// under the License.
31
//
32
33
#include <string>
34
#include <vector>
35
36
#include <glog/logging.h>
37
#include <gmock/gmock.h>
38
39
#include "yb/util/logging_test_util.h"
40
#include "yb/util/logging.h"
41
#include "yb/util/monotime.h"
42
43
DECLARE_string(vmodule);
44
45
using std::string;
46
using std::vector;
47
48
// LoggingTest is not actually an integration test, but we put it here, so it will be linked with
49
// all libraries used for YB cluster processes, because static object initialization in thse
50
// libraries could cause logging issues.
51
// For example: https://github.com/yugabyte/yugabyte-db/issues/3176
52
53
namespace yb {
54
55
// Test the YB_LOG_EVERY_N_SECS(...) macro.
56
1
TEST(LoggingTest, TestThrottledLogging) {
57
1
  StringVectorSink sink;
58
1
  ScopedRegisterSink srs(&sink);
59
60
771
  for (int i = 0; i < 10000; i++) {
61
771
    YB_LOG_EVERY_N_SECS(INFO, 1) << "test" << THROTTLE_MSG;
62
771
    SleepFor(MonoDelta::FromMilliseconds(1));
63
771
    if (sink.logged_msgs().size() >= 2) break;
64
771
  }
65
1
  const vector<string>& msgs = sink.logged_msgs();
66
1
  ASSERT_GE(msgs.size(), 2);
67
68
  // The first log line shouldn't have a suppression count.
69
1
  EXPECT_THAT(msgs[0], testing::ContainsRegex("test$"));
70
  // The second one should have suppressed at least three digits worth of log messages.
71
1
  EXPECT_THAT(msgs[1], testing::ContainsRegex("\\[suppressed [0-9]{3,} similar messages\\]"));
72
1
}
73
74
1
TEST(LoggingTest, VModule) {
75
1
  google::FlagSaver flag_saver;
76
77
1
  FLAGS_vmodule = "logging-test=1";
78
79
1
  ASSERT_TRUE(VLOG_IS_ON(1));
80
81
1
  constexpr auto kPattern = "vmodule-test";
82
1
  StringVectorSink sink;
83
1
  ScopedRegisterSink srs(&sink);
84
85
1
  VLOG(1) << kPattern;
86
87
1
  const vector<string>& msgs = sink.logged_msgs();
88
89
1
  ASSERT_GE(msgs.size(), 1);
90
91
1
  EXPECT_THAT(msgs[0], testing::HasSubstr(kPattern));
92
1
}
93
94
} // namespace yb