-
Notifications
You must be signed in to change notification settings - Fork 10
Update dependencies, add scripts to generate report and updated README #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JoaoBraveCoding
wants to merge
12
commits into
observatorium:master
Choose a base branch
from
JoaoBraveCoding:LOG-5940
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4a1ebcb
feat: adds generate_report python script
JoaoBraveCoding b103da2
feat: added more metrics to the ingestion benchmark
JoaoBraveCoding 25c5702
feat: started collecting gateway resources for ingestion
JoaoBraveCoding 2684cdd
fix: fix query path RBAC + fix generate_report legend
JoaoBraveCoding 73caefc
update README.md
JoaoBraveCoding 57b3217
Merge branch 'LOG-5940' of github.com:JoaoBraveCoding/loki-benchmarks…
JoaoBraveCoding 07633d4
feat: added made initialDelay configurable
JoaoBraveCoding 34577b6
Apply suggestions from code review
JoaoBraveCoding f8cec6f
update links & env var
JoaoBraveCoding 76960f6
fix ci
JoaoBraveCoding dbacd63
update dependencies
JoaoBraveCoding 17d82f1
fix lint errors
JoaoBraveCoding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import os | ||
import sys | ||
import argparse | ||
from docx import Document | ||
from docx.shared import Inches | ||
from docx.oxml.ns import qn | ||
from docx.oxml import OxmlElement | ||
import markdown | ||
from bs4 import BeautifulSoup | ||
|
||
def add_hyperlink(paragraph, url, text, color="0000FF", underline=True): | ||
part = paragraph.part | ||
r_id = part.relate_to(url, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', is_external=True) | ||
|
||
hyperlink = OxmlElement('w:hyperlink') | ||
hyperlink.set(qn('r:id'), r_id) | ||
|
||
new_run = OxmlElement('w:r') | ||
rPr = OxmlElement('w:rPr') | ||
|
||
if color: | ||
c = OxmlElement('w:color') | ||
c.set(qn('w:val'), color) | ||
rPr.append(c) | ||
|
||
if underline: | ||
u = OxmlElement('w:u') | ||
u.set(qn('w:val'), 'single') | ||
rPr.append(u) | ||
|
||
new_run.append(rPr) | ||
new_run.text = text | ||
hyperlink.append(new_run) | ||
|
||
paragraph._p.append(hyperlink) | ||
return hyperlink | ||
|
||
def add_table_of_contents(soup, doc): | ||
toc = soup.find('ul') | ||
if toc: | ||
for li in toc.find_all('li'): | ||
link = li.find('a') | ||
if link and link['href'].startswith('#'): | ||
heading_text = link.text | ||
toc_paragraph = doc.add_paragraph() | ||
add_hyperlink(toc_paragraph, f'#{heading_text}', heading_text) | ||
|
||
def add_markdown_to_docx(md_content, doc, base_path): | ||
html = markdown.markdown(md_content) | ||
soup = BeautifulSoup(html, 'html.parser') | ||
|
||
heading_map = {} | ||
toc_inserted = False | ||
|
||
for element in soup: | ||
if element.name == 'h1': | ||
paragraph = doc.add_heading(element.text, level=1) | ||
heading_map[element.text] = paragraph | ||
elif element.name == 'h2': | ||
paragraph = doc.add_heading(element.text, level=2) | ||
heading_map[element.text] = paragraph | ||
if element.text.lower() == 'table of contents' and not toc_inserted: | ||
add_table_of_contents(soup, doc) | ||
toc_inserted = True | ||
elif element.name == 'h3': | ||
paragraph = doc.add_heading(element.text, level=3) | ||
heading_map[element.text] = paragraph | ||
elif element.name == 'p': | ||
paragraph = doc.add_paragraph(element.text) | ||
for img in element.find_all('img'): | ||
img_src = img['src'].lstrip('./') | ||
img_path = os.path.join(base_path, img_src) | ||
if os.path.exists(img_path): | ||
doc.add_picture(img_path, width=Inches(5.0)) | ||
else: | ||
paragraph.add_run(f"[Image not found: {img_path}]") | ||
elif element.name == 'ul' and not toc_inserted: | ||
for li in element.find_all('li'): | ||
doc.add_paragraph(li.text, style='ListBullet') | ||
elif element.name == 'ol': | ||
for li in element.find_all('li'): | ||
doc.add_paragraph(li.text, style='ListNumber') | ||
elif element.name == 'a': | ||
paragraph = doc.add_paragraph() | ||
add_hyperlink(paragraph, element['href'], element.text) | ||
|
||
for heading_text, paragraph in heading_map.items(): | ||
bookmark = OxmlElement('w:bookmarkStart') | ||
bookmark.set(qn('w:id'), str(hash(heading_text))) | ||
bookmark.set(qn('w:name'), heading_text) | ||
paragraph._p.insert(0, bookmark) | ||
bookmark_end = OxmlElement('w:bookmarkEnd') | ||
bookmark_end.set(qn('w:id'), str(hash(heading_text))) | ||
paragraph._p.append(bookmark_end) | ||
|
||
def convert_readme_to_docx(readme_dir, output_path): | ||
readme_path = os.path.join(readme_dir, 'README.md') | ||
if not os.path.exists(readme_path): | ||
print(f"README.md not found in {readme_dir}") | ||
return | ||
|
||
with open(readme_path, 'r') as file: | ||
md_content = file.read() | ||
|
||
doc = Document() | ||
add_markdown_to_docx(md_content, doc, readme_dir) | ||
doc.save(output_path) | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Convert a README.md file to a DOCX file.') | ||
parser.add_argument('readme_dir', type=str, help='Directory containing the README.md file') | ||
args = parser.parse_args() | ||
|
||
readme_dir = args.readme_dir | ||
output_path = os.path.join(readme_dir, 'README.docx') | ||
convert_readme_to_docx(readme_dir, output_path) | ||
print(f"Converted README.md in {readme_dir} to {output_path}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import json | ||
import matplotlib.pyplot as plt | ||
from jinja2 import Template | ||
import os | ||
import argparse | ||
import yaml | ||
|
||
# Parse command-line arguments | ||
parser = argparse.ArgumentParser(description='Generate benchmark report from measurements.json') | ||
parser.add_argument('dir_paths', type=str, nargs='+', help='Paths to the directories containing the measurements.json files') | ||
args = parser.parse_args() | ||
|
||
# Function to load benchmark description from benchmark.yaml | ||
def load_benchmark_description(dir_path): | ||
yaml_path = os.path.join(dir_path, 'benchmark.yaml') | ||
with open(yaml_path) as f: | ||
benchmark_data = yaml.safe_load(f) | ||
return benchmark_data.get('scenarios', {}).get('ingestionPath', {}).get('description', 'Unknown Benchmark') | ||
|
||
# Function to plot a measurement and save as image | ||
def plot_measurement(measurements, output_dir, plot_index): | ||
plt.figure(figsize=(10, 6)) | ||
for measurement, description in measurements: | ||
name = measurement['Name'] | ||
values = measurement['Values'] | ||
units = measurement['Units'] | ||
annotations = measurement.get('Annotations', []) | ||
|
||
# Generate time values for x-axis starting from 3 minutes | ||
time_values = [(i + 1) * 3 for i in range(len(values))] | ||
|
||
plt.plot(time_values, values, marker='o', label=description) | ||
|
||
plt.title(f'{name}') | ||
plt.xlabel('Time (minutes)') | ||
plt.ylabel(f'{units}') | ||
plt.legend() | ||
plt.grid(True) | ||
|
||
plot_filename = os.path.join(output_dir, f'plot_{plot_index}.png') | ||
plt.savefig(plot_filename) | ||
plt.close() | ||
|
||
return f'./plots/plot_{plot_index}.png', f'{name}' | ||
|
||
# Collect all measurements from the provided directories | ||
all_measurements = {} | ||
for dir_path in args.dir_paths: | ||
json_path = os.path.join(dir_path, 'measurements.json') | ||
with open(json_path) as f: | ||
data = json.load(f) | ||
|
||
benchmark_description = load_benchmark_description(dir_path) | ||
measurements = data[0]['Measurements'] | ||
|
||
for measurement in measurements: | ||
name = measurement['Name'] | ||
if name not in all_measurements: | ||
all_measurements[name] = [] | ||
all_measurements[name].append((measurement, benchmark_description)) | ||
|
||
# Determine the parent directory for the README and plots | ||
parent_dir = os.path.commonpath(args.dir_paths) | ||
output_dir = os.path.join(parent_dir, 'plots') | ||
os.makedirs(output_dir, exist_ok=True) | ||
|
||
# Plot all measurements and save images | ||
plot_files = [] | ||
for plot_index, (name, measurements) in enumerate(all_measurements.items()): | ||
plot_file, plot_title = plot_measurement(measurements, output_dir, plot_index) | ||
plot_files.append((plot_title, plot_file)) | ||
|
||
# Load README template | ||
template_path = 'reports/README.template' | ||
with open(template_path) as f: | ||
template_content = f.read() | ||
|
||
# Render README with plots | ||
template = Template(template_content) | ||
rendered_readme = template.render(plots=plot_files) | ||
|
||
# Save rendered README | ||
readme_path = os.path.join(parent_dir, 'README.md') | ||
with open(readme_path, 'w') as f: | ||
f.write(rendered_readme) | ||
|
||
print(f"Plots and README.md generated successfully in {parent_dir}.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.