YugabyteDB (2.13.0.0-b42, bfc6a6643e7399ac8a0e81d06a3ee6d6571b33ab)

Coverage Report

Created: 2022-03-09 17:30

/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
17.5k
    error_counter_(METRIC_glog_error_messages.Instantiate(entity)) {
58
17.5k
  }
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
30.7M
                    const char* message, size_t message_len) override {
64
65
30.7M
    Counter* c;
66
30.7M
    switch (severity) {
67
29.7M
      case google::INFO:
68
29.7M
        c = info_counter_.get();
69
29.7M
        break;
70
1.03M
      case google::WARNING:
71
1.03M
        c = warning_counter_.get();
72
1.03M
        break;
73
30.5k
      case google::ERROR:
74
30.5k
        c = error_counter_.get();
75
30.5k
        break;
76
285
      default:
77
285
        return;
78
30.7M
    }
79
80
30.7M
    c->Increment();
81
30.7M
  }
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
17.5k
  : sink_(new MetricsSink(entity)) {
91
17.5k
  google::AddLogSink(sink_.get());
92
17.5k
}
93
94
200
ScopedGLogMetrics::~ScopedGLogMetrics() {
95
200
  google::RemoveLogSink(sink_.get());
96
200
}
97
98
99
100
} // namespace yb