Skip to content

Commit 0c31f84

Browse files
committed
fixed GH-7 by coping with commas in timestamps (and testing them in 001)
1 parent c70d35c commit 0c31f84

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

CHANGELOG.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
3.8 (in development)
22
--------------------
3+
Enhancements:
34
- Added support for analysing logs containing the "id | " prefixes added when running a correlator inside docker.
4-
- Improved sort order of log files to only include time unless we know there are multiple different instances.
5+
- Improved sort order of log files to only include time when we know there are multiple different instances.
6+
- Moved sent events/tx to a secondary axis so that the event rate chart lines up with other charts with two axes.
7+
8+
Bug fixes:
59
- Fixed error when si/so have NaN values which can happen occasionally.
10+
- Fixed parse failures when lines contain "," in the timestamp which can happen with some Java logging libraries.
611

712
3.7
813
---

apamax/log_analyzer.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
It extracts and summarizes information from status lines and other log messages.
66
77
8-
Copyright (c) 2019-2021 Software AG, Darmstadt, Germany and/or its licensors
8+
Copyright (c) 2019-2022 Software AG, Darmstadt, Germany and/or its licensors
99
1010
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
1111
file except in compliance with the License. You may obtain a copy of the License at
@@ -19,7 +19,7 @@
1919
2020
"""
2121

22-
__date__ = '2020-07-10'
22+
__date__ = '2022-01-07'
2323
__version__ = '3.8.dev/'+__date__
2424
__author__ = "Apama community"
2525
__license__ = "Apache 2.0"
@@ -137,7 +137,7 @@ class LogLine(object):
137137
@ivar extraLines: unassigned, or a list of strings which are extra lines logically part of this one (typically for warn/error stacks etc)
138138
"""
139139
# date level thread apama-ctrl/std cat message
140-
LINE_REGEX = re.compile(r'(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d[.]\d\d\d) ([A-Z#]+) +\[([^\]]+)\] ([^-]*)-( <[^>]+>)? (.*)')
140+
LINE_REGEX = re.compile(r'(\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d[.,]\d\d\d) ([A-Z#]+) +\[([^\]]+)\] ([^-]*)-( <[^>]+>)? (.*)')
141141

142142
__slots__ = ['line', 'lineno', 'message', 'level', '__details', 'extraLines'] # be memory-efficient
143143
def __init__(self, line, lineno):
@@ -218,9 +218,16 @@ def getDateTime(self):
218218
return det['datetime']
219219

220220
try:
221-
d = datetime.datetime.strptime(self.getDetails()['datetimestring'], '%Y-%m-%d %H:%M:%S.%f')
221+
dts = det['datetimestring']
222+
if not dts:
223+
log.debug('Cannot find date time string in line: %s', det['datetimestring'], self.line)
224+
return None
225+
if dts[19:20] == ',':
226+
dts = dts[:19]+'.'+dts[20:] # for german locales
227+
d = datetime.datetime.strptime(dts, '%Y-%m-%d %H:%M:%S.%f')
228+
#assert d, line
222229
except Exception as ex: # might not be a valid line
223-
log.debug('Cannot parse date time from "%s": %s - from line: %s', self.getDetails()['datetimestring'], ex, self.line)
230+
log.debug('Cannot parse date time from "%s": %s - from line: %s', det['datetimestring'], ex, self.line)
224231
return None
225232
det['datetime'] = d
226233
return d
@@ -1076,15 +1083,17 @@ def handleWarnOrError(self, file, isError, line, **extra):
10761083

10771084
tracker = tracker.setdefault(normmsg, {})
10781085
tracker = tracker.setdefault(self.currentpath, {})
1086+
#assert line.getDateTime(), line
10791087
if not tracker:
10801088
tracker['first'] = tracker['last'] = line
10811089
tracker['count'] = 1
10821090
tracker['samples'] = []
10831091
else:
1084-
if tracker['first'].getDateTime() > line.getDateTime():
1085-
tracker['first'] = line
1086-
if tracker['last'].getDateTime() < line.getDateTime():
1087-
tracker['last'] = line
1092+
if line.getDateTime():
1093+
if tracker['first'].getDateTime() and tracker['first'].getDateTime() > line.getDateTime():
1094+
tracker['first'] = line
1095+
if tracker['last'].getDateTime() and tracker['last'].getDateTime() < line.getDateTime():
1096+
tracker['last'] = line
10881097
tracker['count'] += 1
10891098

10901099
tracker['samples'].append(line)

tests/correctness/Cor_001/Input/mycorrelator.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@
7474
2019-04-09 13:57:22.774 ##### [32376] - Component ID: correlator (correlator/6677878040143647328/6677878040143647328)
7575
2019-04-09 13:57:22.774 ##### [32376] - Correlator, version 10.3.1.0.348044, running
7676
2019-04-09 13:57:27.770 INFO [22872] - Correlator Status: sm=3 nctx=4 ls=50000 rq=6 iq=7 oq=8 icq=9 lcn="slowest consumer" lcq=10 lct=12.34 rx=13 tx=14 rt=15 nc=16 vm=17111222 pm=18111 runq=19 si=20.61 so=21.6 srn="slowest consumer" srq=22 jvm=231111
77-
2019-04-09 13:57:32.770 INFO [22872] - Correlator Status: sm=0 nctx=1 ls=10 rq=0 iq=0 oq=0 icq=0 lcn="<none>" lcq=0 lct=0.0 rx=0 tx=0 rt=0 nc=0 vm=22580 pm=25312 runq=0 si=0.0 so=0.0 srn="<none>" srq=0 jvm=0
77+
2019-04-09 13:57:32,770 INFO [22872] - Correlator Status: sm=0 nctx=1 ls=10 rq=0 iq=0 oq=0 icq=0 lcn="<none>" lcq=0 lct=0.0 rx=0 tx=0 rt=0 nc=0 vm=22580 pm=25312 runq=0 si=0.0 so=0.0 srn="<none>" srq=0 jvm=0
7878
2019-04-09 13:57:37.769 INFO [22872] - Correlator Status: sm=0 nctx=1 ls=0 rq=0 iq=0 oq=0 icq=0 lcn="<none>" lcq=0 lct=0.0 rx=0 tx=0 rt=0 nc=0 vm=22580 pm=25312 runq=0 si=0.4 so=0.0 srn="<none>" srq=0 jvm=0

tests/correctness/Cor_001/pysystest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Check for correct extraction of main "Correlator Status:" lines, using canned log files.
88
Touch-tests CSV output format and JSON.
99
This is a general test that does not hardcode specific values.
10+
Also checks that lines with a comma delimiter for milliseconds can be read OK (happens with some Java logging
11+
libraries in European locales)
1012
]]>
1113
</purpose>
1214
</description>

0 commit comments

Comments
 (0)