Skip to content

Commit cc3c5e8

Browse files
author
droberts2013
committed
Add xld-config-hash-utility
1 parent cff6a8d commit cc3c5e8

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gradle
2+
build
3+
temp
4+
work
5+
supervisord.*

xld-config-hash-utility/README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# XLD config hash utility
2+
3+
## Usage
4+
5+
1. Apply this entry to the conf/logback.xml file for each node to be examined.
6+
7+
<logger name="com.xebialabs.deployit.engine.tasker.distribution.versioning" level="trace" />
8+
9+
2. Copy the logs to a host with a Python 2.7 installation.
10+
11+
3. Configure the properties file with the appropriate start and end datetimes for the two logs.
12+
13+
4. Run the following after substituting your log file names:
14+
15+
python xld-config-hash-utility.py deployit_master.log deployit_worker.log.
16+
17+
5. Review the output for configuration hash mismatches.
18+
19+
Sample output:
20+
21+
~~~
22+
$ python xld-config-hash-utility.py deployit_master.log deployit_worker.log
23+
24+
Read 187 lines from /Users/droberts/2023Jul01-config-hash-utility/deployit_master.log
25+
Processing 159 hashed items from /Users/droberts/2023Jul01-config-hash-utility/deployit_master.log
26+
27+
Read 193 lines from /Users/droberts/2023Jul01-config-hash-utility/deployit_worker.log
28+
Processing 159 hashed items from /Users/droberts/2023Jul01-config-hash-utility/deployit_worker.log
29+
30+
-----------------------------------------------------------------------------------
31+
32+
Compare /Users/droberts/2023Jul01-config-hash-utility/deployit_master.log (left) to /Users/droberts/2023Jul01-config-hash-utility/deployit_worker.log (right)
33+
Match 157 items in left log to right log
34+
35+
Mismatch on item xl.scheduler.system.akka.loggers:"akka.event.Logging$DefaultLogger" in left file but not in right file
36+
37+
Mismatch on item database-plugin-9.5.1.xldp:
38+
left file hash is f283c1bd26665a47a4c5df98655514634a17bd5bb5f2a78370f3457034c4aa15
39+
right file hash is f283c1bd26665a47a4c5df98655514634a17bd5bb5f2a78370f3457034c4aa10
40+
41+
Mismatch on item jee-plugin-9.5.1.xldp:
42+
left file hash is d8b4c2ea2dae5e72991da2f2fac387eb22286de24316c2ac00887a01fb57d140
43+
right file hash is d8b4c2ea2dae5e72991da2f2fac387eb22286de24316c2ac00887a01fb57d141
44+
45+
-----------------------------------------------------------------------------------
46+
47+
Compare /Users/droberts/2023Jul01-config-hash-utility/deployit_worker.log (left) to /Users/droberts/2023Jul01-config-hash-utility/deployit_master.log (right)
48+
Match 157 items in left log to right log
49+
50+
Mismatch on item xl.scheduler.system.akka.loggers:"akka.event.slf4j.Slf4jLogger" in left file but not in right file
51+
52+
Mismatch on item database-plugin-9.5.1.xldp:
53+
left file hash is f283c1bd26665a47a4c5df98655514634a17bd5bb5f2a78370f3457034c4aa10
54+
right file hash is f283c1bd26665a47a4c5df98655514634a17bd5bb5f2a78370f3457034c4aa15
55+
56+
Mismatch on item jee-plugin-9.5.1.xldp:
57+
left file hash is d8b4c2ea2dae5e72991da2f2fac387eb22286de24316c2ac00887a01fb57d141
58+
right file hash is d8b4c2ea2dae5e72991da2f2fac387eb22286de24316c2ac00887a01fb57d140
59+
60+
-----------------------------------------------------------------------------------
61+
62+
Execution completed
63+
~~~
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[CommonSection]
2+
datetime_pattern=([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})
3+
hash_pattern=Using hash ([0-9a-f]{64}) for (\S+)
4+
divider_char=-
5+
divider_length=83
6+
7+
[Log1Section]
8+
start_datetime=2020-02-05 00:00:00.000
9+
end_datetime=2020-02-05 23:59:59.999
10+
11+
[Log2Section]
12+
start_datetime=2020-02-05 00:00:00.000
13+
end_datetime=2020-02-05 23:59:59.999
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Run as python xld-config-hash-utility.py log1.log log2.log
2+
# Configure xld-config-hash-utility.properties file in this way:
3+
# [CommonSection]
4+
# datetime_pattern=([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})
5+
# hash_pattern=Using hash ([0-9a-f]{64}) for (\S+)
6+
#
7+
# [Log1Section]
8+
# start_datetime=2020-02-05 00:00:00.000
9+
# end_datetime=2020-02-05 23:59:59.999
10+
#
11+
# [Log2Section]
12+
# start_datetime=2020-02-05 00:00:00.000
13+
# end_datetime=2020-02-05 23:59:59.999
14+
#
15+
16+
import re
17+
import sys
18+
import ConfigParser
19+
20+
def create_map(pattern, log_file_path, key_hash_map, start_datetime, end_datetime):
21+
line_count = 0
22+
matched_line_count = 0
23+
log_file = open(log_file_path)
24+
for line in log_file:
25+
line_count += 1
26+
m = pattern.match(line)
27+
if m:
28+
matched_line_count += 1
29+
line_datetime = m.group(1)
30+
line_hash = m.group(2)
31+
line_itemname = m.group(3)
32+
if m.group(1) >= start_datetime and m.group(1) <= end_datetime:
33+
key_hash_map[m.group(3)] = m.group(2)
34+
log_file.close()
35+
print "Read %s lines from %s" % (line_count, log_file_path)
36+
print "Processing %s hashed items from %s" % (matched_line_count, log_file_path)
37+
38+
def compare_maps(key_hash_map_1, key_hash_map_2):
39+
print "Match %d items in left log to right log\n" % len(key_hash_map_1)
40+
for key in key_hash_map_1.keys():
41+
if key in key_hash_map_2.keys():
42+
if key_hash_map_1[key] == key_hash_map_2[key]:
43+
continue
44+
else:
45+
print "Mismatch on item %s:\nleft file hash is %s\nright file hash is %s\n" % (key, key_hash_map_1[key], key_hash_map_2[key])
46+
else:
47+
print "Mismatch on item %s in left file but not in right file\n" % key
48+
49+
config = ConfigParser.RawConfigParser()
50+
config.read('xld-config-hash-utility.properties')
51+
52+
datetime_pattern = config.get('CommonSection', 'datetime_pattern')
53+
hash_pattern = config.get('CommonSection', 'hash_pattern')
54+
pattern = re.compile(datetime_pattern + ".*" + hash_pattern + ".*")
55+
56+
log1_map = {}
57+
log2_map = {}
58+
divider = config.get('CommonSection', 'divider_char') * int(config.get('CommonSection', 'divider_length')) + "\n"
59+
print ""
60+
create_map(pattern, sys.argv[1], log1_map, config.get('Log1Section', 'start_datetime'), config.get('Log1Section', 'end_datetime'))
61+
print ""
62+
create_map(pattern, sys.argv[2], log2_map, config.get('Log1Section', 'start_datetime'), config.get('Log1Section', 'end_datetime'))
63+
print "\n" + divider
64+
print "Compare %s (left) to %s (right)" % (sys.argv[1], sys.argv[2])
65+
compare_maps(log1_map, log2_map)
66+
print divider
67+
print "Compare %s (left) to %s (right)" % (sys.argv[2], sys.argv[1])
68+
compare_maps(log2_map, log1_map)
69+
print divider
70+
print "Execution completed"

0 commit comments

Comments
 (0)