Skip to content
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

Implement the report using the Tern #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kairoaraujo
Copy link
Contributor

This commit implements the report using Tern
The reports use the concurrent.futures, but instead of building
all the implementation for it, we use flask-executer that makes the
implementation on top of Flask.

All the report requests go to the tern-tasks (Futures) and are
handled such as a Celery implementation.
All tasks start with the status 'UNKNOWN', which means that the task
has no defined status until the tern-tasks start processing it.
Once the task is in picked up by the tern-tasks it is moved to
'RUNNING'.
If the processing finishes, the status is moved to 'FINISH'
independently of the task content/result. Here the status is for
the task itself.
The FAIL status is given when the task cannot finish its routine.

The Tern, for now, is called using subprocess, and the output is
handled by the stdout and stderr.
The initial API specification was changed a bit for more clearness.

How to run as Docker container was added to the README.md.

Signed-off-by: Kairo de Araujo [email protected]

Kairo de Araujo added 2 commits March 10, 2022 09:22
This commit implements the report using Tern
The reports use the ``concurrent.futures``, but instead of building
all the implementation for it, we use flask-executer that makes the
implementation on top of Flask.

All the report requests go to the ``tern-tasks`` (Futures) and are
handled such as a Celery implementation.
https://docs.celeryproject.org/en/stable/reference/celery.states.html#misc
All tasks start with the status 'PENDING', which means that the task
has no defined status until the ``tern-tasks`` knows it.
Once the task is in picked up by the ``tern-tasks`` it is moved to
'RUNNING'.
If the processing finishes, the status is moved to 'SUCCESS'
independently of the task content/result. Here the status is for
the task itself.
The 'FAILURE' status is given when the task cannot finish its
routine.

The Tern, for now, is called using ``subprocess``, and the output is
handled by the stdout and stderr.
The initial API specification was changed a bit for more clearness.

How to run as Docker container was added to the ``README.md``.

Signed-off-by: Kairo de Araujo <[email protected]>
The logic is easy, but add some quick reference.

Signed-off-by: Kairo de Araujo <[email protected]>
Kairo de Araujo added 4 commits March 10, 2022 09:38
Fix the invalid UNKNOWN status. Correct initial status is PENDING.
This issue causes HTTP 500 when requested the status endpoint.

Signed-off-by: Kairo de Araujo <[email protected]>
Missing License header in the Makefile was added.

Signed-off-by: Kairo de Araujo <[email protected]>
This commit adds to tox.ini the unit tests.
It guarantee that the tests will run in the CI if new changes or tests
are added.

Signed-off-by: Kairo de Araujo <[email protected]>
This commit adds all the tern-rest-api reports implementation tests
covering 100%

Adjusts the repository to use Docker.

Signed-off-by: Kairo de Araujo <[email protected]>
@kairoaraujo kairoaraujo marked this pull request as ready for review March 18, 2022 16:46
The documentation offline is available on
http://tern-tools.github.io/tern-rest-api and tests to see if the API
documentation is updated is a must.

The Makefile contains the entry to build the offline documentation.

Signed-off-by: Kairo de Araujo <[email protected]>
@nishakm
Copy link

nishakm commented Mar 22, 2022

@kairoaraujo how can I test this PR against my changes here? https://github.com/nishakm/tern/tree/api

else:
report = tern(command)

return report
Copy link
Contributor Author

@kairoaraujo kairoaraujo Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nisha

You can modify this function logic.
Instead of calling tern(command), it could call the tern library API.
Also, modify the submit() to build the needed arguments for the tern library API instead command.

Having It in a specific function (see tern line 38) is even better to handle the possible exceptions cases and make task management consistent.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions on how to test the API other than using curl from the command line?

Copy link
Contributor Author

@kairoaraujo kairoaraujo Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can even use the service itself.
The swagger documentation has the option "try it" for each endpoint when the application runs, and it works fine.
The second option is using postman.

Comment on lines +12 to 14
tern_app.config["TERN_API_CACHE_DIR"] = os.getenv("TERN_API_CACHE_DIR")
tern_app.config["TERN_DEFAULT_REGISTRY"] = os.getenv("TERN_DEFAULT_REGISTRY")

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache directory can be retrieved from tern using tern.utils.rootfs.get_working_directory(). You may also want to add a note in the README about setting the TERN_DEFAULT_REGISTRY value when not working with the docker container.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nishakm, sorry for my late reply.
I'm not sure we are talking about the same caching directory here.

  1. The reports generated by the API use this cache
  2. This cache will be stored inside the container, the path given is inside the container, and the variable is to allow the user to use specific data storage and manage it.

I think it is possible to combine both caching, maybe a new issue for it?

I will document the default settings in the README.

Simple document the container evironment variables in the README.md

Two variables can be used to change the default value.
- ``TERN_API_CACHE_DIR``: The directory where the tern reports are cached.
Default: ``/var/opt/tern-rest-api/cache``
- ``TERN_DEFAULT_REGISTRY``: Optional default registry to use when no registry
is passed to the API requests. Default: ``docker.io``

Signed-off-by: Kairo de Araujo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants