Python script for test Api Service Endpoint by launch remote test query

Grixis
Grixis PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 82 ✭✭✭✭✭

Is it possible to call End point de service API queries on a Node design instance with the client's python api?

I'd like to be able to run a python script when evaluating API services that would briefly execute an adapted test query to check the solvency of the service before pushing it to the deployer.

Best,

Randy

Best Answer

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,162 Neuron
    Answer ✓

    Well at the end of the day the APIs are on the Designer node and are simple REST APIs. So nothing stops you from writing your own test framework using Python's requests package. You may be able to pull the tests themselves using the Dataiku Python API and then run them manually via Python's requests package. But it seems this is a lot of work where you can simple install the API node somewhere, deploy your APIs and test them using the Dataiku Python APIs.

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,162 Neuron

    Yes you can do this. The Design Node come with it's own embedded API Node and this can be used for testing. Once you developed your API service create a few test queries in the Endpoint tab. Then run them to confirm your service works.

    The action of running a test will start the embedded API Node. You can also click on the Actions button and select "start Dev Server". Once the embedded API Node server it's started you can click again in the Action button to find out the port the server it's running on. Unluke the proper API Node the embedded API Node runs on a random port:

    Once you have the port number you can build a sample curl command for instance to call your API service:

    curl -X GET "http://localhost:API_service_port/public/api/v1/{serviceId}/{endpointId}/run/?param1=10&param2=20&param3=30"
    

  • Grixis
    Grixis PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 82 ✭✭✭✭✭
  • Grixis
    Grixis PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 82 ✭✭✭✭✭

    Hello @Turribeach,

    Thank you very much for your answer.

    In my case I already define test queries on each of my endpoints in Design, but my question was specifically for 'run test query' of each.
    I mean, without having to go to each of the projects and endpoints, I'd like to have something with the dataiku python api, why not in a visual component such as a Macro or Application, in which I call the test queries and return the response “Dev server is running” or "failed running".

    If you have a proposal for this I'd be really grateful!

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,162 Neuron

    My bad, I didn't read your post properly. What you want to do can be done indeed from the API. Here is the API method you need to use:

    https://developer.dataiku.com/latest/api-reference/python/api-services.html#dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.run_test_queries

  • Grixis
    Grixis PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 82 ✭✭✭✭✭

    Hey, Thank you I'm working on it for the moment I can't exploit it properly for my problem,

    Get you in touch.

    Best,

  • Grixis
    Grixis PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 82 ✭✭✭✭✭

    I'm back and I think I've failed. It seems that this run_test_queries() function only works in the deployer node, so I haven't found a way to call a query test from a project endpoint at the design node level.

  • Grixis
    Grixis PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 82 ✭✭✭✭✭

    Perhaps these informations have their importance on this topic;

    Before V13 at Deployer Node Level the test_query attribut was not associated with a deployment. (In my case in a hook as a post deployment step)

    ref : class  dataikuapi.dss.apideployer.DSSAPIDeployerDeployment

    And <V12.2 there is a bug about run test queries on multi-enpoints API service. (Kind of services I tried to test)

Setup Info
    Tags
      Help me…