Skip to content

Commit

Permalink
feat(app): version endpoint (#938)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Feb 28, 2022
1 parent 0a8b42b commit 4c2b26d
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 180 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
helm-chart
Dockerfile
.travis.yml
travis-deploy.sh
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ telepresence.log
helm-chart/renku-notebooks/charts/*.tgz
git-https-proxy/node_modules/

# JetBrains IDEs
.idea

# Created by https://www.gitignore.io/api/vim,linux,emacs,macos,python,sublimetext,visualstudiocode
# Edit at https://www.gitignore.io/?templates=vim,linux,emacs,macos,python,sublimetext,visualstudiocode

Expand Down
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ptvsd = "~=4.2"
importlib-metadata = "*"
typed-ast = "*"
typing-extensions = "*"
semver = "*"

[requires]

Expand Down
365 changes: 187 additions & 178 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions helm-chart/renku-notebooks/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ spec:
value: {{ .Values.enforceCPULimits | quote }}
- name: S3_MOUNTS_ENABLED
value: {{ .Values.cloudstorage.s3.enabled | quote }}
- name: NOTEBOOKS_SERVICE_VERSION
value: {{ .Values.image.tag | quote }}
ports:
- name: http
containerPort: 8000
Expand Down
2 changes: 2 additions & 0 deletions renku_notebooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ServerOptionsUI,
FailedParsing,
AutosavesList,
VersionResponse,
)
from .api.notebooks import (
user_servers,
Expand Down Expand Up @@ -148,6 +149,7 @@ def register_swagger(app):
spec.components.schema("ServerOptionsUI", schema=ServerOptionsUI)
spec.components.schema("FailedParsing", schema=FailedParsing)
spec.components.schema("AutosavesList", schema=AutosavesList)
spec.components.schema("VersionResponse", schema=VersionResponse)
# Register endpoints
with app.test_request_context():
spec.path(view=user_server)
Expand Down
33 changes: 33 additions & 0 deletions renku_notebooks/api/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ServersGetRequest,
ServersGetResponse,
ServerLogs,
VersionResponse,
)
from .classes.server import UserServer
from .classes.storage import Autosave
Expand All @@ -41,6 +42,38 @@
bp = Blueprint("notebooks_blueprint", __name__, url_prefix=config.SERVICE_PREFIX)


@bp.route("/version")
def version():
"""
Return notebook services version.
---
get:
description: Information about notebooks service.
responses:
200:
description: Notebooks service info.
content:
application/json:
schema: VersionResponse
"""
info = {
"name": "renku-notebooks",
"versions": [
{
"version": config.NOTEBOOKS_SERVICE_VERSION,
"data": {
"anonymousSessionsEnabled": config.ANONYMOUS_SESSIONS_ENABLED,
"cloudstorageEnabled": {
"s3": config.S3_MOUNTS_ENABLED,
},
},
}
],
}
return VersionResponse().dump(info), 200


@bp.route("servers", methods=["GET"])
@use_args(ServersGetRequest(), location="query", as_kwargs=True)
@authenticated
Expand Down
23 changes: 23 additions & 0 deletions renku_notebooks/api/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,26 @@ class AutosavesList(Schema):
if config.S3_MOUNTS_ENABLED
else LaunchNotebookRequestWithoutS3
)


class NotebooksServiceInfo(Schema):
"""Various notebooks service info."""

anonymousSessionsEnabled = fields.Boolean(required=True)
cloudstorageEnabled = fields.Dict(
required=True, keys=fields.String, values=fields.Boolean
)


class NotebooksServiceVersions(Schema):
"""Notebooks service version and info."""

data = fields.Nested(NotebooksServiceInfo, required=True)
version = fields.String(required=True)


class VersionResponse(Schema):
"""The response for /version endpoint."""

name = fields.String(required=True)
versions = fields.List(fields.Nested(NotebooksServiceVersions), required=True)
2 changes: 2 additions & 0 deletions renku_notebooks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@
ENFORCE_CPU_LIMITS = os.getenv("ENFORCE_CPU_LIMITS", "off")
CURRENT_RESOURCE_SCHEMA_VERSION = "1"
S3_MOUNTS_ENABLED = os.getenv("S3_MOUNTS_ENABLED", "false").lower() == "true"

NOTEBOOKS_SERVICE_VERSION = os.getenv("NOTEBOOKS_SERVICE_VERSION", "0.0.0")
24 changes: 23 additions & 1 deletion tests/integration/test_session_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,38 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for Notebook Services API"""

import os

import pytest
import requests
import os
import semver


def test_can_check_health():
response = requests.get(os.environ["NOTEBOOKS_BASE_URL"] + "/health")
assert response.status_code == 200


def test_version_endpoint(base_url):
response = requests.get(f"{base_url}/version")

assert response.status_code == 200
assert response.json()["name"] == "renku-notebooks"

versions = response.json()["versions"]
assert isinstance(versions, list)

version = versions[0]["version"]
assert version != "0.0.0"
assert semver.VersionInfo.isvalid(version)

data = versions[0]["data"]
assert type(data.get("anonymousSessionsEnabled")) is bool
storage = data.get("cloudstorageEnabled", {})
assert type(storage.get("s3")) is bool


def test_getting_session_and_logs_after_creation(
headers, launch_session, delete_session, base_url, valid_payload, gitlab_project
):
Expand Down

0 comments on commit 4c2b26d

Please sign in to comment.