Skip to content

Commit c086f22

Browse files
committed
Add "start" annotation to event rate chart, showing each time a correlator process was started or restarted.
1 parent ac02ae4 commit c086f22

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
3.4
22
---
3+
- Add "start" annotation to event rate chart, showing each time a correlator process was started or restarted.
34
- Remove .zip (or similar) extension from auto-generated output directory name when unpacking an archive, to avoid confusion.
45
- Avoid negative event rate values when a correlator restart occurs within a log file.
56

apamax/log_analyzer.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ def handleFileStarted(self, file, **extra):
595595
file['totalStatusLinesInFile'] = 0
596596

597597
file['startupStanzas'] = [{}]
598+
file['annotations'] = []
598599
file['inStartupStanza'] = False
599600

600601
file['connectionMessages'] : List = []
@@ -781,6 +782,12 @@ def decideColumns(status):
781782

782783
seconds = status['epoch secs'] # floating point epoch seconds
783784

785+
if (not previousStatus) or (previousStatus['restarts'] != len(file['startupStanzas'])):
786+
if file['startupStanzas'][-1].get('startTime'): # this is the only place we can add the annotation given we must associated it with a timestamp that's in the data series
787+
file['annotations'].append({'x': line.getDateTime(), 'shortText':'start', 'width':40,
788+
'text': f"Correlator process {'started' if len(file['startupStanzas'])==1 else 'restart #%s'%(len(file['startupStanzas'])-1)}"})
789+
790+
784791
if previousStatus is None:
785792
if file['startTime'] is not None:
786793
secsSinceLast = status['epoch secs']-file['startTime'].replace(tzinfo=datetime.timezone.utc).timestamp()
@@ -1667,7 +1674,7 @@ def v(val, cls='overview-value', fmt=None): # values are escaped then put into a
16671674
ss = file['startupStanzas'][stanzaNum]
16681675

16691676
ov['Process id:'] = f"{v(ss.get('pid') or '?',cls='overview-pid overview-value')}"
1670-
if stanzaNum > 0: ov['Process id:']+= " "+v(f"restart #{stanzaNum+1}")+f" at {v(ss.get('startTime'))} (line {ss['startLineNumber']})"
1677+
if stanzaNum > 0: ov['Process id:']+= " "+v(f"restart #{stanzaNum}")+f" at {v(ss.get('startTime'))} (line {ss['startLineNumber']})"
16711678

16721679
ov['Apama version:'] = f"{v(ss.get('apamaVersion', '?'))}{', apama-ctrl: '+v(file['apamaCtrlVersion']) if file.get('apamaCtrlVersion') else ''}; running on {v(ss.get('OS'))}"
16731680
ov['Log timezone:'] = f"{v(ss.get('utcOffset') or '?')}"+(f" ({v(ss.get('timezoneName'))})" if ss.get('timezoneName') else '')
@@ -1935,8 +1942,16 @@ def writeOverviewHTMLForAllFiles(self, overviewHTML, **extra):
19351942
shutil.copyfileobj(datafile, out)
19361943
os.remove(tmpfile)
19371944
out.write('],\n'+json.dumps(options)[:-1]+',"legendFormatter":legendFormatter}'+'\n);\n')
1938-
out.write('\ncharts.push(g); </script>\n')
1945+
out.write('\ncharts.push(g);\n')
1946+
if c == 'rates':
1947+
for a in file['annotations']:
1948+
dt = a['x']
1949+
a['x'] = f"new Date({dt.year},{dt.month-1},{dt.day},{dt.hour},{dt.minute},{dt.second}).getTime()"
1950+
a.update({'series':'rx /sec', 'attachAtBottom':True})
1951+
out.write('g.setAnnotations('+re.sub('"(new [^"]*)"', "\\1", json.dumps(file['annotations'])+')'))
1952+
out.write('</script>\n')
19391953

1954+
19401955
out.write(self.HTML_END)
19411956
if os.path.exists(os.path.join(self.outputdir, 'tmp')):
19421957
shutil.rmtree(os.path.join(self.outputdir, 'tmp'))

tests/correctness/Cor_012/Reference/ref-overview.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
Notable: noLicenseConstrainedMode
1212
Clean shutdown: Requested at Mon 2019-10-14 22:26:59 (reason: I want you to shut down)
1313

14-
Process id: 14572 restart #2 at Mon 2019-10-14 22:27:06 (line 65)
14+
Process id: 14572 restart #1 at Mon 2019-10-14 22:27:06 (line 65)
1515

16-
Process id: 66760 restart #3 at Mon 2019-10-14 22:27:11 (line 128)
16+
Process id: 66760 restart #2 at Mon 2019-10-14 22:27:11 (line 128)
1717

1818

1919
- #02 correlator-10.3.1.0-win.log
@@ -63,4 +63,4 @@
6363
Fri 2019-10-04 19:02:53 to 19:03:04 (=0:00:10)
6464

6565

66-
Generated by Apama log analyzer v3.4.dev/2020-01-02.
66+
Generated by Apama log analyzer v3.4.dev/2020-02-07.

tests/correctness/Cor_012/run.py

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def validate(self):
5252
for statusline in s:
5353
for k in ['interval secs', 'rx /sec', 'tx /sec', 'log lines /sec']:
5454
self.assertEval('{val} >= 0', val=statusline[k], key=k)
55+
56+
# check for annotations for start and restart on chart
57+
self.assertGrep(outputdir+'/overview.html', expr='setAnnotations[(].*new Date[(]2019,9,14,22,26,59[)].*"text": "Correlator process started"')
58+
self.assertGrep(outputdir+'/overview.html', expr='setAnnotations[(].*new Date[(]2019,9,14,22,27,6[)].*"text": "Correlator process restart #1"')
5559

5660
# strip out the stats since we test them elsewhere
5761
self.copy(outputdir+'/overview.txt', 'overview-without-stats.txt', mappers=[

0 commit comments

Comments
 (0)