Fix data accuracy bugs

There are two data accuracy bugs fixed here. First we address the scroll
context ttl. It was only 1m which seems to not be enough for some of our
queries and we get inconsistent results. Bump that up to 10 minutes
which is what the opensearch api docs use. Note we try to clear the
scroll context when we are done but we don't appear to have enough
permissions for that so we leave the code commented out.

Then the other issue had to do with calculating the median patchsets per
review. We need to index into the sorted list not th raw list to find
the median. Fix that.

Change-Id: Iac0df1b476bf88552e829a3d1edb41790a09d99b
This commit is contained in:
Clark Boylan committed 2025-05-29 14:15:58 -07:00
1 parent fc8c98e2df
commit 7e9649038a
1 file changed
+24 -11
+24 -11
View File
@@ -238,7 +238,8 @@ def calculate_merge_time(client, project_name, start_date, end_date):
closed_query["size"] = 100
times_to_merge = []
r = client.search(index='openstack_gerrit', scroll='1m', body=closed_query)
r = client.search(index='openstack_gerrit',
scroll='10m', body=closed_query)
hits = r['hits']['hits']
while hits:
for hit in hits:
@@ -250,8 +251,10 @@ def calculate_merge_time(client, project_name, start_date, end_date):
# Beware normal pagination. Results are not consistent.
# Use scroll instead
r = client.scroll(scroll_id=r["_scroll_id"], scroll="1m")
r = client.scroll(scroll_id=r["_scroll_id"], scroll="10m")
hits = r['hits']['hits']
# TODO(clarkb) currently lacking permissions to do this.
# client.clear_scroll(scroll_id=r["_scroll_id"])
times_sorted = sorted(times_to_merge)
middle = math.floor(len(times_to_merge) / 2)
median = times_sorted[middle]
@@ -275,7 +278,8 @@ def calculate_time_to_review(client, project_name, start_date, end_date):
closed_query["size"] = 100
times_to_review = []
r = client.search(index='openstack_gerrit', scroll='1m', body=closed_query)
r = client.search(index='openstack_gerrit',
scroll='10m', body=closed_query)
hits = r['hits']['hits']
while hits:
for hit in hits:
@@ -289,8 +293,10 @@ def calculate_time_to_review(client, project_name, start_date, end_date):
# Beware normal pagination. Results are not consistent.
# Use scroll instead
r = client.scroll(scroll_id=r["_scroll_id"], scroll="1m")
r = client.scroll(scroll_id=r["_scroll_id"], scroll="10m")
hits = r['hits']['hits']
# TODO(clarkb) currently lacking permissions to do this.
# client.clear_scroll(scroll_id=r["_scroll_id"])
times_sorted = sorted(times_to_review)
middle = math.floor(len(times_to_review) / 2)
median = datetime.timedelta(days=times_sorted[middle])
@@ -312,7 +318,8 @@ def calculate_patchset_per_review(client, project_name, start_date, end_date):
closed_query["size"] = 100
patchsets_list = []
r = client.search(index='openstack_gerrit', scroll='1m', body=closed_query)
r = client.search(index='openstack_gerrit',
scroll='10m', body=closed_query)
hits = r['hits']['hits']
while hits:
for hit in hits:
@@ -321,11 +328,13 @@ def calculate_patchset_per_review(client, project_name, start_date, end_date):
# Beware normal pagination. Results are not consistent.
# Use scroll instead
r = client.scroll(scroll_id=r["_scroll_id"], scroll="1m")
r = client.scroll(scroll_id=r["_scroll_id"], scroll="10m")
hits = r['hits']['hits']
# TODO(clarkb) currently lacking permissions to do this.
# client.clear_scroll(scroll_id=r["_scroll_id"])
patchsets_sorted = sorted(patchsets_list)
middle = math.floor(len(patchsets_list) / 2)
median = patchsets_list[middle]
median = patchsets_sorted[middle]
average = sum(patchsets_sorted) / len(patchsets_sorted)
return median, average
@@ -343,7 +352,7 @@ def collect_reviewers(client, project_name, start_date, end_date):
query["size"] = 100
reviewers = set()
r = client.search(index='openstack_gerrit', scroll='1m', body=query)
r = client.search(index='openstack_gerrit', scroll='10m', body=query)
hits = r['hits']['hits']
while hits:
for hit in hits:
@@ -352,8 +361,10 @@ def collect_reviewers(client, project_name, start_date, end_date):
# Beware normal pagination. Results are not consistent.
# Use scroll instead
r = client.scroll(scroll_id=r["_scroll_id"], scroll="1m")
r = client.scroll(scroll_id=r["_scroll_id"], scroll="10m")
hits = r['hits']['hits']
# TODO(clarkb) currently lacking permissions to do this.
# client.clear_scroll(scroll_id=r["_scroll_id"])
return len(reviewers), None
@@ -370,7 +381,7 @@ def collect_maintainers(client, project_name, start_date, end_date):
query["size"] = 100
maintainers = set()
r = client.search(index='openstack_gerrit', scroll='1m', body=query)
r = client.search(index='openstack_gerrit', scroll='10m', body=query)
hits = r['hits']['hits']
while hits:
for hit in hits:
@@ -384,8 +395,10 @@ def collect_maintainers(client, project_name, start_date, end_date):
# Beware normal pagination. Results are not consistent.
# Use scroll instead
r = client.scroll(scroll_id=r["_scroll_id"], scroll="1m")
r = client.scroll(scroll_id=r["_scroll_id"], scroll="10m")
hits = r['hits']['hits']
# TODO(clarkb) currently lacking permissions to do this.
# client.clear_scroll(scroll_id=r["_scroll_id"])
return len(maintainers), None