-
Notifications
You must be signed in to change notification settings - Fork 19
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
PerfCi Grafana Dashboard: add grafonnet support #641
PerfCi Grafana Dashboard: add grafonnet support #641
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want Thiru and/or Kelly to review this too.
tests/integration/benchmark_runner/common/grafana/test_grafana_operations.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a number of changes as specified.
90079f5
to
4be1b8d
Compare
6e0b783
to
8adf676
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still have some comments to address.
# Pull the latest changes from the remote main branch | ||
git pull origin main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment still applies.
|
||
class GrafanaOperations: | ||
""" | ||
This class responsible for Grafana operations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment still applies.
:return: | ||
""" | ||
dashboard_list = [] | ||
headers = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment still applies.
8adf676
to
9beaa30
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more quoting changes and one Content-Type:
:return: | ||
""" | ||
dashboard_list = [] | ||
headers = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the http request have a Content-Type: header since you expect JSON?
import re | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="Extract text between <<EOT and EOT in input file.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if EOT is somehow present inside a line as opposed to being part of a here document.
7d69b94
to
20ac6a6
Compare
@RobertKrawitz, The parser works fine and parse it without EOT |
Just because it works in a test doesn't mean that it's robust. You need to handle edge cases and unexpected input too. |
@RobertKrawitz here is an example for the code we extract: Before extracting:
After extracting:
|
What happens if the original is:
You'll then get
as your output. I know this is unlikely, but the code needs to be written defensively. |
@RobertKrawitz. so what do you recommend ? |
20ac6a6
to
89cdb95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few more quotes, and still need to fix the EOT regex.
ELASTICSEARCH_USER: ${{ secrets.PERF_ELASTICSEARCH_USER }} | ||
ELASTICSEARCH_PASSWORD: ${{ secrets.PERF_ELASTICSEARCH_PASSWORD }} | ||
run: | | ||
python $GITHUB_WORKSPACE/grafonnet_generator/grafana/update_versions_main_libsonnet.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be quoted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
c22c934
to
6350059
Compare
|
No, the regular expression can be more intelligent, to only recognize the second EOT on a line by itself. Rather than
it can be something like
to pick up the final EOT on a line by itself, either at the very end or between two newlines. |
The other way to do it is to pass it to a shell to parse, but then you have to trust that the code isn't going to do something it shouldn't. Parsing the here doc is reasonable enough, just do it correctly. |
benchmark_runner/grafana/Dockerfile
Outdated
|
||
ENV PATH="/root/go/bin:${PATH}" | ||
|
||
CMD ["/bin/sh", "-c", "terraform init; make > dashboard.txt; python3 extract_dashboard.py dashboard.txt dashboard.json; terraform destroy -auto-approve > /dev/null 2>&1"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a much easier way you can do this:
CMD ["/bin/sh", "-c", "terraform init; make |/bin/sh > dashboard.json; terraform destroy -auto-approve > /dev/null 2>&1"]
and then you won't need extract_dashboard.py at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried, but its not working:
[root@6e8e49594c69 app]# make |/bin/sh > dashboard.json
/bin/sh: line 1: $'\E[0m\E[1mdata.jsonnet_file.dashboard:': command not found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the extract code for suffix: \nEOT\n
r'dashboard = <<EOT(.*?)\nEOT\n'
That should solve the EOT issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to run terraform init --no-color
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From https://developer.hashicorp.com/terraform/cli/commands/init
-no-color Disable color codes in the command output.
You're much better off not trying to fight what terraform init is trying to do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
terraform apply -auto-approve -json => generates corrupted json output
Generates a different json format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/root/grafonnet/ => You should put your local path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Local path to what?
Can you include the generated JSON?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dashboard.json
I have pushed the changes, think its good enough for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix it up so that extract_dashboard.py doesn't need an input and an output file, and you don't have to create a temporary file in the makefile. Yes, this will work, but it's one more place that something might go wrong in the future.
11fb3a9
to
3ec88b4
Compare
import re, sys, json | ||
|
||
if len(sys.argv) != 3: | ||
raise ValueError('Usage: python extract_dictionary.py input_file output_file') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called extract_dashboard. But you really should have it read from stdin and write to stdout, without any temporary files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a few minutes to write this correctly to not need input and output files. It's very little work and it's one less piece of technical debt that builds up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RobertKrawitz You right, remove temporary file, read directly from stdin
terraform apply -auto-approve | python3 extract_dashboard.py dashboard.json
277e1e2
to
413fbf2
Compare
import re, sys, json | ||
|
||
if len(sys.argv) != 3: | ||
raise ValueError('Usage: python extract_dictionary.py input_file output_file') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a few minutes to write this correctly to not need input and output files. It's very little work and it's one less piece of technical debt that builds up.
benchmark_runner/grafana/Dockerfile
Outdated
|
||
ENV PATH="/root/go/bin:${PATH}" | ||
|
||
CMD ["/bin/sh", "-c", "terraform init; make > dashboard.txt; python3 extract_dashboard.py dashboard.txt dashboard.json; terraform destroy -auto-approve > /dev/null 2>&1"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix it up so that extract_dashboard.py doesn't need an input and an output file, and you don't have to create a temporary file in the makefile. Yes, this will work, but it's one more place that something might go wrong in the future.
@cd jsonnet/ && \ | ||
jb install && \ | ||
cd ../ && \ | ||
terraform apply -auto-approve | python3 extract_dashboard.py dashboard.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best for extract_dashboard.py to simply send its output to stdout (so you could easily e. g. pipe it through jq
if desired), but I'll accept this, as it avoids the temporary file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RobertKrawitz, no temporary file, pls see latest fix.
terraform apply -auto-approve | python3 extract_dashboard.py dashboard.json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I approved it as such. I still think that extract_dashboard should write to stdout rather than to a separate file; that would allow you to e. g. process it further through jq, but I've accepted it as it avoids the temporary file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to dashboard.json file?
We must have this file because we use it to update Grafana dashboard in case of changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but you could write it as
terraform apply -auto-approve | python3 extract_dashboard.py > dashboard.json
Then if you want at some point to process the JSON with jq downstream of extract_dashboard.py you can simply add it to the pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You right, updated it !!!
413fbf2
to
d74fa44
Compare
d74fa44
to
262f104
Compare
""" | ||
This class updates grafana dashboard with last value mappings from ElasticSearch | ||
""" | ||
MAX_VERSION_LEN = 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this for (please document it).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RobertKrawitz, add document.
Prevent error messages from being displayed instead of versions in case of a connection issue
25e6c44
to
2bdfe38
Compare
bea25ee
to
216b7bf
Compare
I have added jsonnetfile.lock.json file to point on specific grafonnet version instead of latest. |
216b7bf
to
3f3ac05
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless this is required by jsonnet, please change the version file name from jsonnetfile.lock.json to jsonnetfile.version.json or similar. lock
implies concurrency control of some kind, which isn't what this is about.
3f3ac05
to
677f078
Compare
677f078
to
7480434
Compare
Type of change
Note: Fill x in []
Description
Adding grafonnet support:
[ Important: Currently the implementation is against testing dashboard, once all working update PerfCi dashboard ]
For security reasons, all pull requests need to be approved first before running any automated CI