[LNT] r312199 - Endpoint to get to graph url for a sample.

Chris Matthews via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 17:28:59 PDT 2017


Author: cmatthews
Date: Wed Aug 30 17:28:59 2017
New Revision: 312199

URL: http://llvm.org/viewvc/llvm-project?rev=312199&view=rev
Log:
Endpoint to get to graph url for a sample.

When you have gotten samples from the API, it is useful to be able to
get their graphs.  This endpoint will take a sample ID and field name,
as given from the API, and redirect you to the graph page for the data
set that sample comes from.

Modified:
    lnt/trunk/lnt/server/ui/views.py
    lnt/trunk/tests/server/ui/V4Pages.py

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=312199&r1=312198&r2=312199&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Wed Aug 30 17:28:59 2017
@@ -680,6 +680,45 @@ BaselineLegendItem = namedtuple('Baselin
 LegendItem = namedtuple('LegendItem', 'machine test_name field_name color url')
 
 
+ at v4_route("/graph_for_sample/<int:sample_id>/<string:field_name>")
+def v4_graph_for_sample(sample_id, field_name):
+    """Redirect to a graph of the data that a sample and field came from.
+
+    When you have a sample from an API call, this can get you into the LNT graph
+    page, for that sample.  Extra args are passed through, to allow the caller
+    to customize the graph page displayed, with for example run highlighting.
+
+    :param sample_id: the sample ID from the database, obtained from the API.
+    :param field_name: the name of the field.
+    :return: a redirect to the graph page for that sample and field.
+
+    """
+    ts = request.get_testsuite()
+    target_sample = ts.query(ts.Sample).get(sample_id)
+    if not target_sample:
+        abort(404, "Could not find sample id: {}".format(sample_id))
+
+    # Get the field index we are interested in.
+    field = None
+    for f in target_sample.get_primary_fields():
+        if f.name == field_name:
+            field = f
+            break
+    if not field:
+        abort(400, "Could not find field {}".format(field_name))
+    field_index = field.index
+
+    kwargs = {'plot.0': '{machine_id}.{test_id}.{field_id}'.format(
+        machine_id=target_sample.run.machine.id,
+        test_id=target_sample.test_id,
+        field_id=field_index)}
+    # Pass request args through, so you can add graph options.
+    kwargs.update(request.args)
+
+    graph_url = v4_url_for('.v4_graph', **kwargs)
+    return redirect(graph_url)
+
+
 @v4_route("/graph")
 def v4_graph():
     from lnt.server.ui import util

Modified: lnt/trunk/tests/server/ui/V4Pages.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/tests/server/ui/V4Pages.py?rev=312199&r1=312198&r2=312199&view=diff
==============================================================================
--- lnt/trunk/tests/server/ui/V4Pages.py (original)
+++ lnt/trunk/tests/server/ui/V4Pages.py Wed Aug 30 17:28:59 2017
@@ -585,5 +585,17 @@ def main():
     resp = check_code(client, '/ping')
     assert resp.data == "pong"
 
+    # Check we can convert a sample into a graph page.
+    graph_to_sample = check_code(client, '/db_default/v4/nts/graph_for_sample/10/compile_time?foo=bar',
+                                 expected_code=HTTP_REDIRECT)
+    assert graph_to_sample.headers['Location'] == "http://localhost/db_default/v4/nts/graph?foo=bar&plot.0=2.6.2"
+
+    # Check that is we ask for a sample or invalid field, we explode with 400s.
+    check_code(client, '/db_default/v4/nts/graph_for_sample/10000/compile_time?foo=bar',
+               expected_code=HTTP_NOT_FOUND)
+    check_code(client, '/db_default/v4/nts/graph_for_sample/10/not_a_metric?foo=bar',
+               expected_code=HTTP_BAD_REQUEST)
+
+
 if __name__ == '__main__':
     main()




More information about the llvm-commits mailing list