YugabyteDB (2.13.1.0-b60, 21121d69985fbf76aa6958d8f04a9bfa936293b5)

Coverage Report

Created: 2022-03-22 16:43

/Users/deen/code/yugabyte-db/src/yb/server/glog_metrics.cc
Line
Count
Source (jump to first uncovered line)
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
#include "yb/server/glog_metrics.h"
33
34
#include <glog/logging.h>
35
36
#include "yb/util/metrics.h"
37
38
METRIC_DEFINE_counter(server, glog_info_messages,
39
                      "INFO-level Log Messages", yb::MetricUnit::kMessages,
40
                      "Number of INFO-level log messages emitted by the application.");
41
42
METRIC_DEFINE_counter(server, glog_warning_messages,
43
                      "WARNING-level Log Messages", yb::MetricUnit::kMessages,
44
                      "Number of WARNING-level log messages emitted by the application.");
45
46
METRIC_DEFINE_counter(server, glog_error_messages,
47
                      "ERROR-level Log Messages", yb::MetricUnit::kMessages,
48
                      "Number of ERROR-level log messages emitted by the application.");
49
50
namespace yb {
51
52
class MetricsSink : public google::LogSink {
53
 public:
54
  explicit MetricsSink(const scoped_refptr<MetricEntity>& entity) :
55
    info_counter_(METRIC_glog_info_messages.Instantiate(entity)),
56
    warning_counter_(METRIC_glog_warning_messages.Instantiate(entity)),
57
26.3k
    error_counter_(METRIC_glog_error_messages.Instantiate(entity)) {
58
26.3k
  }
59
60
  virtual void send(google::LogSeverity severity, const char* full_filename,
61
                    const char* base_filename, int line,
62
                    const struct ::tm* tm_time,
63
72.9M
                    const char* message, size_t message_len) override {
64
65
72.9M
    Counter* c;
66
72.9M
    switch (severity) {
67
67.2M
      case google::INFO:
68
67.2M
        c = info_counter_.get();
69
67.2M
        break;
70
5.68M
      case google::WARNING:
71
5.68M
        c = warning_counter_.get();
72
5.68M
        break;
73
36.5k
      case google::ERROR:
74
36.5k
        c = error_counter_.get();
75
36.5k
        break;
76
1.23k
      default:
77
1.23k
        return;
78
72.9M
    }
79
80
72.9M
    c->Increment();
81
72.9M
  }
82
83
 private:
84
  scoped_refptr<Counter> info_counter_;
85
  scoped_refptr<Counter> warning_counter_;
86
  scoped_refptr<Counter> error_counter_;
87
};
88
89
ScopedGLogMetrics::ScopedGLogMetrics(const scoped_refptr<MetricEntity>& entity)
90
26.3k
  : sink_(new MetricsSink(entity)) {
91
26.3k
  google::AddLogSink(sink_.get());
92
26.3k
}
93
94
242
ScopedGLogMetrics::~ScopedGLogMetrics() {
95
242
  google::RemoveLogSink(sink_.get());
96
242
}
97
98
99
100
} // namespace yb