Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-5745

Implement ingestion code for the QA results

    XMLWordPrintable

    Details

    • Type: Story
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      The initial database model was implemented in DM-5728 and outputs of the QA analysis code are being produced by the work described in http://dmtn-008.lsst.io/en/latest/

      In this ticket we plan to implement and API for listing and creating jobs, metrics and measurements so that a job or the QA analysis code can register this information in the dashboard app.

        Attachments

          Activity

          Hide
          afausti Angelo Fausti added a comment - - edited

          Writing API for listing and creating jobs, metrics and measurements, the gerenal structure of the API for now is

          /api/
               /job/
                           <id>
              /metric/
                           <id>
             /measurement/
                          <id>
          
          

          this is meant to be used with a single dataset see http://sqr-009.lsst.io/en/latest/

          Show
          afausti Angelo Fausti added a comment - - edited Writing API for listing and creating jobs, metrics and measurements, the gerenal structure of the API for now is /api/ /job/ <id> /metric/ <id> /measurement/ <id> this is meant to be used with a single dataset see http://sqr-009.lsst.io/en/latest/
          Hide
          afausti Angelo Fausti added a comment -

          Initial API is done and testing code was added see description at http://sqr-009.lsst.io/en/latest/

          Show
          afausti Angelo Fausti added a comment - Initial API is done and testing code was added see description at http://sqr-009.lsst.io/en/latest/
          Hide
          jhoblitt Joshua Hoblitt added a comment -

          I have made some comments on the PR, including a successful test report. However, I am not familiar (at all) with django. I think it would be worth while if we can identify some who is to take a quick look.

          Show
          jhoblitt Joshua Hoblitt added a comment - I have made some comments on the PR, including a successful test report. However, I am not familiar (at all) with django. I think it would be worth while if we can identify some who is to take a quick look.
          Hide
          afausti Angelo Fausti added a comment - - edited

          Joshua Hoblitt Implemented a nested serializer for the job API endpoint. Now it is possible to POST job and measurement data in a single request, the JSON looks like

          job = {
                   "name": "ci_cfht",
                   "build": "1",
                   "runtime": "2016-04-24T19:26:12.561564Z",
                   "url": "https://ci.lsst.codes/job/ci_cfht/1/",
                   "status": 0,
                   "measurements": [{ "metric": "PA1", "value": 5.0}]
                }
          
          

          the documentation was updated too. http://sqr-009.lsst.io/en/latest/#level-0-qa

          I have pushed that to the ticket branch.

          If you run the dashboard you can test this by inserting a metric at http://localhost:8000/api/metric/

          {
                         'metric': 'PA1',
                         'description': 'Photometric Repeatability',
                         'units': 'millimag',
                         'minimum': '8',
                         'design': '5',
                         'stretch': '3',
                         'user': '10',
          }
          
          

          and then a job at http://localhost:8000/api/job/

           
          {
                   "name": "ci_cfht",
                   "build": "1",
                   "runtime": "2016-04-24T19:26:12.561564Z",
                   "url": "https://ci.lsst.codes/job/ci_cfht/1/",
                   "status": 0,
                   "measurements": [{ "metric": "PA1", "value": 5.0}]
          }
           
          
          

          J Matt Peterson [X] the issue I mentioned to you on Friday is related to that, I could not make the python requests work with the nested serializer. If you do

          >>> import requests
          >>> response = requests.get('http://localhost:8000/api/')
          >>> api = response.json()
          >>> job = { "name": "ci_cfht", "build": "1", "runtime": "2016-04-24T19:26:12.561564Z", "url": "https://ci.lsst.codes/job/ci_cfht/1/", "status": 0, "measurements": [{ "metric": "PA1", "value": 5.0}] }
          >>> requests.post(api['job'], data=job, auth=(TEST_USER, TEST_PASSWD))
          
          

          the result is

           
          HTTP 200 OK
          Allow: GET, POST, HEAD, OPTIONS
          Content-Type: application/json
          Vary: Accept
           
          {
              "count": 1,
              "next": null,
              "previous": null,
              "results": [
                  {
                      "name": "ci_cfht",
                      "build": "1",
                      "runtime": "2016-04-24T23:22:22.729289Z",
                      "url": "https://ci.lsst.codes/job/ci_cfht/1/",
                      "status": 0,
                      "measurements": [],
                      "links": {
                          "self": "http://localhost:8000/api/job/1/"
                      }
                  }
              ]
          }
          
          

          i.e., the content of measurements is not inserted...

          As far as I can tell the serializer seems right

          >>> from dashboard.serializers import JobSerializer
          >>> s = JobSerializer()
          >>> print(repr(s))
          JobSerializer():
              name = CharField(max_length=32)
              build = CharField(max_length=16)
              runtime = DateTimeField(read_only=True)
              url = CharField(style={'base_template': 'textarea.html'})
              status = IntegerField(required=False)
              measurements = MeasurementSerializer(many=True):
                  metric = PrimaryKeyRelatedField(queryset=Metric.objects.all())
                  value = FloatField()
              links = SerializerMethodField()
           
          >>> job= {'url': 'https://ci.lsst.codes/job/ci_cfht/1/', 'runtime': '2016-04-24T19:26:12.561564Z', 'measurements': [{'metric': 'PA1', 'value': '5.0'}], 'build': '1', 'name': 'ci_cfht', 'status': '0'}
          >>> s = JobSerializer(data=job)
          >>> s.is_valid()
          True
          >>> s.save()
          <Job: 1>
          
          

          this way or submitting data from the API form (http://localhost:8000/api/job/) the 'measurements' list s inserted as expected.

          Show
          afausti Angelo Fausti added a comment - - edited Joshua Hoblitt Implemented a nested serializer for the job API endpoint. Now it is possible to POST job and measurement data in a single request, the JSON looks like job = { "name" : "ci_cfht" , "build" : "1" , "runtime" : "2016-04-24T19:26:12.561564Z" , "url" : "https://ci.lsst.codes/job/ci_cfht/1/" , "status" : 0 , "measurements" : [{ "metric" : "PA1" , "value" : 5.0 }] } the documentation was updated too. http://sqr-009.lsst.io/en/latest/#level-0-qa I have pushed that to the ticket branch. If you run the dashboard you can test this by inserting a metric at http://localhost:8000/api/metric/ { 'metric' : 'PA1' , 'description' : 'Photometric Repeatability' , 'units' : 'millimag' , 'minimum' : '8' , 'design' : '5' , 'stretch' : '3' , 'user' : '10' , } and then a job at http://localhost:8000/api/job/   { "name" : "ci_cfht" , "build" : "1" , "runtime" : "2016-04-24T19:26:12.561564Z" , "url" : "https://ci.lsst.codes/job/ci_cfht/1/" , "status" : 0 , "measurements" : [{ "metric" : "PA1" , "value" : 5.0 }] }   J Matt Peterson [X] the issue I mentioned to you on Friday is related to that, I could not make the python requests work with the nested serializer. If you do >>> import requests >>> response = requests.get( 'http://localhost:8000/api/' ) >>> api = response.json() >>> job = { "name" : "ci_cfht" , "build" : "1" , "runtime" : "2016-04-24T19:26:12.561564Z" , "url" : "https://ci.lsst.codes/job/ci_cfht/1/" , "status" : 0 , "measurements" : [{ "metric" : "PA1" , "value" : 5.0 }] } >>> requests.post(api[ 'job' ], data=job, auth=(TEST_USER, TEST_PASSWD)) the result is   HTTP 200 OK Allow: GET, POST, HEAD, OPTIONS Content-Type: application/json Vary: Accept   { "count" : 1 , "next" : null , "previous" : null , "results" : [ { "name" : "ci_cfht" , "build" : "1" , "runtime" : "2016-04-24T23:22:22.729289Z" , "url" : "https://ci.lsst.codes/job/ci_cfht/1/" , "status" : 0 , "measurements" : [], "links" : { "self" : "http://localhost:8000/api/job/1/" } } ] } i.e., the content of measurements is not inserted... As far as I can tell the serializer seems right >>> from dashboard.serializers import JobSerializer >>> s = JobSerializer() >>> print(repr(s)) JobSerializer(): name = CharField(max_length= 32 ) build = CharField(max_length= 16 ) runtime = DateTimeField(read_only=True) url = CharField(style={ 'base_template' : 'textarea.html' }) status = IntegerField(required=False) measurements = MeasurementSerializer(many=True): metric = PrimaryKeyRelatedField(queryset=Metric.objects.all()) value = FloatField() links = SerializerMethodField()   >>> job= { 'url' : 'https://ci.lsst.codes/job/ci_cfht/1/' , 'runtime' : '2016-04-24T19:26:12.561564Z' , 'measurements' : [{ 'metric' : 'PA1' , 'value' : '5.0' }], 'build' : '1' , 'name' : 'ci_cfht' , 'status' : '0' } >>> s = JobSerializer(data=job) >>> s.is_valid() True >>> s.save() <Job: 1 > this way or submitting data from the API form ( http://localhost:8000/api/job/ ) the 'measurements' list s inserted as expected.
          Hide
          afausti Angelo Fausti added a comment -

          As pointed out by @jmatt in https://github.com/lsst-sqre/qa-dashboard/pull/2 the problem was the requests post call in my tests/test_api.py that used used

           r = requests.post(api['job'], data=job, auth=(TEST_USER, TEST_PASSWD))
          

          changing to

           r = requests.post(api['job'], json=job, auth=(TEST_USER, TEST_PASSWD))
          

          forces the right encoding and the measurements list is correctly inserted by the nested serializer. Examples in the documentation were uptdated accordingly.

          I think we are good to merge this ticket branch to master and move on.

          Show
          afausti Angelo Fausti added a comment - As pointed out by @jmatt in https://github.com/lsst-sqre/qa-dashboard/pull/2 the problem was the requests post call in my tests/test_api.py that used used r = requests.post(api[ 'job' ], data=job, auth=(TEST_USER, TEST_PASSWD)) changing to r = requests.post(api[ 'job' ], json=job, auth=(TEST_USER, TEST_PASSWD)) forces the right encoding and the measurements list is correctly inserted by the nested serializer. Examples in the documentation were uptdated accordingly. I think we are good to merge this ticket branch to master and move on.
          Hide
          afausti Angelo Fausti added a comment -

          Issue with the nested serializer was fixed (see above) now it is possible to insert a job and a list of metrics in a single POST request.

          Show
          afausti Angelo Fausti added a comment - Issue with the nested serializer was fixed (see above) now it is possible to insert a job and a list of metrics in a single POST request.

            People

            Assignee:
            afausti Angelo Fausti
            Reporter:
            afausti Angelo Fausti
            Reviewers:
            J Matt Peterson [X] (Inactive), Joshua Hoblitt
            Watchers:
            Angelo Fausti, Joshua Hoblitt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Jenkins

                No builds found.