-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathcassandra.go
297 lines (265 loc) · 11.6 KB
/
cassandra.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package apps
import (
"context"
"github.com/GoogleCloudPlatform/ops-agent/confgenerator"
"github.com/GoogleCloudPlatform/ops-agent/confgenerator/fluentbit"
"github.com/GoogleCloudPlatform/ops-agent/confgenerator/otel"
)
type MetricsReceiverCassandra struct {
confgenerator.ConfigComponent `yaml:",inline"`
confgenerator.MetricsReceiverSharedJVM `yaml:",inline"`
confgenerator.MetricsReceiverSharedCollectJVM `yaml:",inline"`
}
const defaultCassandraEndpoint = "localhost:7199"
func (r MetricsReceiverCassandra) Type() string {
return "cassandra"
}
func (r MetricsReceiverCassandra) Pipelines(_ context.Context) ([]otel.ReceiverPipeline, error) {
targetSystem := "cassandra"
return r.MetricsReceiverSharedJVM.
WithDefaultEndpoint(defaultCassandraEndpoint).
ConfigurePipelines(
r.TargetSystemString(targetSystem),
[]otel.Component{
otel.NormalizeSums(),
otel.MetricsTransform(
otel.AddPrefix("workload.googleapis.com"),
),
otel.ModifyInstrumentationScope(r.Type(), "1.0"),
},
)
}
func init() {
confgenerator.MetricsReceiverTypes.RegisterType(func() confgenerator.MetricsReceiver { return &MetricsReceiverCassandra{} })
}
type LoggingProcessorCassandraSystem struct {
confgenerator.ConfigComponent `yaml:",inline"`
}
func (LoggingProcessorCassandraSystem) Type() string {
return "cassandra_system"
}
func (p LoggingProcessorCassandraSystem) Components(ctx context.Context, tag string, uid string) []fluentbit.Component {
return javaLogParsingComponents(ctx, p.Type(), tag, uid)
}
type LoggingProcessorCassandraDebug struct {
confgenerator.ConfigComponent `yaml:",inline"`
}
func (LoggingProcessorCassandraDebug) Type() string {
return "cassandra_debug"
}
func (p LoggingProcessorCassandraDebug) Components(ctx context.Context, tag string, uid string) []fluentbit.Component {
return javaLogParsingComponents(ctx, p.Type(), tag, uid)
}
func javaLogParsingComponents(ctx context.Context, processorType, tag, uid string) []fluentbit.Component {
c := confgenerator.LoggingProcessorParseMultilineRegex{
LoggingProcessorParseRegexComplex: confgenerator.LoggingProcessorParseRegexComplex{
Parsers: []confgenerator.RegexParser{
{
// Sample line: INFO [IndexSummaryManager:1] 2021-10-07 12:57:05,003 IndexSummaryRedistribution.java:83 - Redistributing index summaries
// Sample line: WARN [main] 2021-10-07 11:57:01,602 StartupChecks.java:329 - Maximum number of memory map areas per process (vm.max_map_count) 65530 is too low, recommended value: 1048575, you can change it with sysctl.
// Sample line: ERROR [MemtablePostFlush:2] 2021-10-05 01:03:35,424 CassandraDaemon.java:579 - Exception in thread Thread[MemtablePostFlush:2,5,main]
// org.apache.cassandra.io.FSReadError: java.io.IOException: Invalid folder descriptor trying to create log replica /folder/views-9786ac1cdd583201a7cdad556410c985
// at org.apache.cassandra.db.lifecycle.LogReplica.create(LogReplica.java:59)
// at org.apache.cassandra.db.lifecycle.LogReplicaSet.maybeCreateReplica(LogReplicaSet.java:87)
// at org.apache.cassandra.db.lifecycle.LogFile.makeAddRecord(LogFile.java:336)
// at org.apache.cassandra.db.lifecycle.LogFile.add(LogFile.java:310)
Regex: `^(?<level>[A-Z]+)\s+\[(?<module>[^\]]+)\]\s+(?<time>\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d+)\s+(?<message>(?:(?<javaClass>[\w\.]+):(?<lineNumber>\d+))?[\S\s]+)`,
Parser: confgenerator.ParserShared{
TimeKey: "time",
TimeFormat: "%Y-%m-%d %H:%M:%S,%L",
Types: map[string]string{
"lineNumber": "integer",
},
},
},
},
},
Rules: []confgenerator.MultilineRule{
{
StateName: "start_state",
NextState: "cont",
Regex: `^[A-Z]+\s+\[[^\]]+\] \d+`,
},
{
StateName: "cont",
NextState: "cont",
Regex: `^(?![A-Z]+\s+\[[^\]]+\] \d+)`,
},
},
}.Components(ctx, tag, uid)
// Best documentation found for log levels:
// https://docs.datastax.com/en/cassandra-oss/3.0/cassandra/configuration/configLoggingLevels.html#Loglevels
c = append(c,
confgenerator.LoggingProcessorModifyFields{
Fields: map[string]*confgenerator.ModifyField{
"severity": {
CopyFrom: "jsonPayload.level",
MapValues: map[string]string{
"TRACE": "TRACE",
"DEBUG": "DEBUG",
"INFO": "INFO",
"ERROR": "ERROR",
"WARN": "WARNING",
},
MapValuesExclusive: true,
},
InstrumentationSourceLabel: instrumentationSourceValue(processorType),
},
}.Components(ctx, tag, uid)...,
)
return c
}
type LoggingProcessorCassandraGC struct {
confgenerator.ConfigComponent `yaml:",inline"`
}
func (LoggingProcessorCassandraGC) Type() string {
return "cassandra_gc"
}
func (p LoggingProcessorCassandraGC) Components(ctx context.Context, tag string, uid string) []fluentbit.Component {
c := confgenerator.LoggingProcessorParseMultilineRegex{
LoggingProcessorParseRegexComplex: confgenerator.LoggingProcessorParseRegexComplex{
Parsers: []confgenerator.RegexParser{
{
// Compatible with Java versions pre-11
// Vast majority of lines look like the first, with time stopped & time stopping
// Sample line: 2021-10-02T04:18:28.284+0000: 3.315: Total time for which application threads were stopped: 0.0002390 seconds, Stopping threads took: 0.0000281 seconds
// Sample line: 2021-10-05T01:20:52.695+0000: 4.434: [GC (CMS Initial Mark) [1 CMS-initial-mark: 0K(3686400K)] 36082K(4055040K), 0.0130057 secs] [Times: user=0.04 sys=0.00, real=0.01 secs]
// Sample line: 2021-10-05T01:20:52.741+0000: 4.481: [CMS-concurrent-preclean-start]
// Lines may also contain more detailed GC Heap information in the following lines
Regex: `^(?<time>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3,6}(?:Z|[+-]\d{2}:?\d{2})):\s+(?<uptime>\d+\.\d{3,6}):\s+(?<message>(?:Total time for which application threads were stopped: (?<timeStopped>\d+\.\d+) seconds, Stopping threads took: (?<timeStopping>\d+\.\d+)[\s\S]*|[\s\S]+))`,
Parser: confgenerator.ParserShared{
TimeKey: "time",
TimeFormat: "%Y-%m-%dT%H:%M:%S.%L%z",
Types: map[string]string{
"uptime": "float",
"timeStopped": "float",
"timeStopping": "float",
},
},
},
{
// Compatible with Java versions 11+ (see https://bugs.openjdk.org/browse/JDK-8046148)
// Vast majority of lines look like the first, with time stopped & time stopping
// Sample line: [2023-05-16T14:51:23.332+0000][4.595s][5195][5217][info ] Total time for which application threads were stopped: 0.0003091 seconds, Stopping threads took: 0.0000181 seconds
// Sample line: [2023-05-16T14:51:23.332+0000][4.595s][5195][5216][info ] GC(1) Concurrent Abortable Preclean 540.253ms
// Sample line: [2023-05-16T14:51:23.332+0000][4.595s][5195][5217][info ] Application time: 0.0001203 seconds
// Lines may also contain more detailed GC Heap information in the following lines
Regex: `^\[(?<time>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3,6}(?:Z|[+-]\d{2}:?\d{2}))\]\s?\[(?<uptime>\d+\.\d{3,6})s?\]\s?\[(?<pid>\d+)\]\s?\[(?<tid>\d+)\]\s?\[(?<level>\w+)\s?\]\s?(?<message>(?:Total time for which application threads were stopped: (?<timeStopped>\d+\.\d+) seconds, Stopping threads took: (?<timeStopping>\d+\.\d+)[\s\S]*|[\s\S]+))`,
Parser: confgenerator.ParserShared{
TimeKey: "time",
TimeFormat: "%Y-%m-%dT%H:%M:%S.%L%z",
Types: map[string]string{
"uptime": "float",
"pid": "integer",
"tid": "integer",
"timeStopped": "float",
"timeStopping": "float",
},
},
},
},
},
Rules: []confgenerator.MultilineRule{
{
StateName: "start_state",
NextState: "cont",
Regex: `^\[?\d{4}-\d{2}-\d{2}`,
},
{
StateName: "cont",
NextState: "cont",
Regex: `^(?!\[?\d{4}-\d{2}-\d{2})`,
},
},
}.Components(ctx, tag, uid)
// Java11+ gc logs have severity in the log line
// https://bugs.openjdk.org/browse/JDK-8046148
c = append(c,
confgenerator.LoggingProcessorModifyFields{
Fields: map[string]*confgenerator.ModifyField{
"severity": {
CopyFrom: "jsonPayload.level",
MapValues: map[string]string{
"develop": "TRACE",
"trace": "TRACE",
"debug": "DEBUG",
"info": "INFO",
"error": "ERROR",
"warning": "WARNING",
},
MapValuesExclusive: true,
},
InstrumentationSourceLabel: instrumentationSourceValue(p.Type()),
},
}.Components(ctx, tag, uid)...,
)
return c
}
type LoggingReceiverCassandraSystemMixin struct {
confgenerator.LoggingReceiverFilesMixin `yaml:",inline" validate:"structonly"`
}
func (r LoggingReceiverCassandraSystemMixin) Components(ctx context.Context, tag string) []fluentbit.Component {
if len(r.IncludePaths) == 0 {
r.IncludePaths = []string{
// Default log file path on Debian / Ubuntu / RHEL / CentOS
"/var/log/cassandra/system*.log",
// No default install position / log path for SLES
}
}
return r.LoggingReceiverFilesMixin.Components(ctx, tag)
}
type LoggingReceiverCassandraDebugMixin struct {
confgenerator.LoggingReceiverFilesMixin `yaml:",inline" validate:"structonly"`
}
func (r LoggingReceiverCassandraDebugMixin) Components(ctx context.Context, tag string) []fluentbit.Component {
if len(r.IncludePaths) == 0 {
r.IncludePaths = []string{
// Default log file path on Debian / Ubuntu / RHEL / CentOS
"/var/log/cassandra/debug*.log",
// No default install position / log path for SLES
}
}
return r.LoggingReceiverFilesMixin.Components(ctx, tag)
}
type LoggingReceiverCassandraGCMixin struct {
confgenerator.LoggingReceiverFilesMixin `yaml:",inline" validate:"structonly"`
}
func (r LoggingReceiverCassandraGCMixin) Components(ctx context.Context, tag string) []fluentbit.Component {
if len(r.IncludePaths) == 0 {
r.IncludePaths = []string{
// Default log file path on Debian / Ubuntu / RHEL / CentOS for JDK 8
"/var/log/cassandra/gc.log.*.current",
// Default log file path on Debian / Ubuntu / RHEL / CentOS for JDK 11
"/var/log/cassandra/gc.log",
// No default install position / log path for SLES
}
}
return r.LoggingReceiverFilesMixin.Components(ctx, tag)
}
func init() {
confgenerator.LoggingProcessorTypes.RegisterType(func() confgenerator.LoggingProcessor { return &LoggingProcessorCassandraSystem{} })
confgenerator.LoggingProcessorTypes.RegisterType(func() confgenerator.LoggingProcessor { return &LoggingProcessorCassandraDebug{} })
confgenerator.LoggingProcessorTypes.RegisterType(func() confgenerator.LoggingProcessor { return &LoggingProcessorCassandraGC{} })
confgenerator.LoggingReceiverTypes.RegisterType(func() confgenerator.LoggingReceiver {
return &confgenerator.LoggingCompositeReceiver[LoggingReceiverCassandraSystemMixin, LoggingProcessorCassandraSystem]{}
})
confgenerator.LoggingReceiverTypes.RegisterType(func() confgenerator.LoggingReceiver {
return &confgenerator.LoggingCompositeReceiver[LoggingReceiverCassandraDebugMixin, LoggingProcessorCassandraDebug]{}
})
confgenerator.LoggingReceiverTypes.RegisterType(func() confgenerator.LoggingReceiver {
return &confgenerator.LoggingCompositeReceiver[LoggingReceiverCassandraGCMixin, LoggingProcessorCassandraGC]{}
})
}