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

Fastapi confserver no cache #1181

Merged
merged 61 commits into from Mar 7, 2023
Merged

Fastapi confserver no cache #1181

merged 61 commits into from Mar 7, 2023

Conversation

yoavkatzman
Copy link
Contributor

No description provided.

@github-actions

This comment has been minimized.

Signed-off-by: Curiefense Bootstrap Script <yoavk@reblaze.com>
Signed-off-by: Curiefense Bootstrap Script <yoavk@reblaze.com>
@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Mar 2, 2023

Unit Test Statistics

    1 files  1 suites   2m 53s ⏱️
122 tests 7 ✔️ 0 💤 1 ❌ 114 🔥

results for commit d473c4a

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Mar 2, 2023

E2E Test Statistics

    1 files      1 suites   4m 0s ⏱️
260 tests 245 ✔️ 15 💤 0 ❌

Results for commit d473c4a.



## Import all versions
from .v3 import api as api_v3

app = Flask(__name__)
logging.basicConfig(
handlers=[logging.FileHandler("fastapi.log"), logging.StreamHandler()],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need store logs in file? Usually it's enough to just stdout. Not sure

format="[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s",
datefmt="%H:%M:%S",
)
logger = logging.getLogger("filters-maxmind")
Copy link
Collaborator

Choose a reason for hiding this comment

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

maxmind?

logging.basicConfig(
handlers=[logging.FileHandler("fastapi.log"), logging.StreamHandler()],
level=logging.INFO,
format="[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s",
Copy link
Collaborator

Choose a reason for hiding this comment

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

asctime - print timestamp. k8s logs adds it's own timestamps into logs. How do we print logs in other curiefense services - with or without timestamps?

Comment on lines +90 to +93
# TODO - find replacements for got_request_exception and prometheus_flask_exporter
# if options.pdb:
# flask.got_request_exception.connect(drop_into_pdb)
# metrics = PrometheusMetrics(app)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the replacement was found - let's remove commented strings from the code

app.options = options.__dict__
uvicorn.run(app, host=options.host, port=options.port)

# app.run(debug=options.debug, host=options.host, port=options.port)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to leave commented string if it's not functional and not a comment

from curieconf.utils import cloud

# TODO: TEMP DEFINITIONS
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

from flask import Blueprint, request, current_app, abort, make_response
from flask_restx import Resource, Api, fields, marshal, reqparse
from curieconf import utils
# from curieconf import utils
Copy link
Collaborator

Choose a reason for hiding this comment

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

?

Comment on lines +18 to 33
import os

router = APIRouter(prefix="/api/v3")
options = {}
val = os.environ.get("CURIECONF_TRUSTED_USERNAME_HEADER", None)
if val:
options["trusted_username_header"] = val
val = os.environ.get("CURIECONF_TRUSTED_EMAIL_HEADER", None)
if val:
options["trusted_email_header"] = val

import requests
from jsonschema import validate
from pathlib import Path
import json

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's keep an order in imports and code maybe?

  1. python and 3rd party modules
  2. empty line
  3. our modules
  4. 2 empty lines
  5. code

exclude: typing.Any
key: anyTypeUnion
pairwith: typing.Any
tags: List[StrictStr]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This one and threshold was optional (no "required=True") and now it's not. What do we want here?

version: Optional[StrictStr]
# TODO - dt_format="iso8601"
date: Optional[datetime.datetime]
# star_: Optional[List[typing.Any]] = Field(alias="*")
Copy link
Collaborator

Choose a reason for hiding this comment

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

can be deleted

Comment on lines +443 to +449
@router.get(
"/configs/",
tags=[Tags.congifs],
response_model=List[Meta],
response_model_exclude_unset=True,
)
async def configs_get(request: Request):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we had descriptions for fields and methods in the previous version - let's add this here too (for here and all the rest API routes below too)

Comment on lines +507 to +510
if x_fields.startswith(("[", "{", "(")):
x_fields = x_fields[1:-1]
x_fields = x_fields.replace(" ", "")
fields = x_fields.split(",")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Or we need to refactor it, or leave a good comment with in and out examples to understand what's going on here. And probably still comment like # TODO: refactor this in addition

"""Get all versions of a given configuration"""
res = request.app.backend.configs_list_versions(config)

if request.headers.get("X-fields", False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have more elegant way to get headers in FastAPI, take a look

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also this will add it into swagger

config: str, blob: str, version: str, request: Request
):
"""Create a new version for a blob from an old version"""
return request.app.backend.blobs_revert(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way in FastAPI to pass request.app as a dependency?
I suspect so, but not sure. If yes - we may make a lot of places more elegant

Comment on lines +646 to +650
if x_fields:
if x_fields.startswith(("[", "{", "(")):
x_fields = x_fields[1:-1]
x_fields = x_fields.replace(" ", "")
fields = x_fields.split(",")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we had similar function up there. Maybe it's different. If so - need to leave comment with in and out examples and TODO to refactor it

if document not in models:
raise HTTPException(404, "document does not exist")
res = request.app.backend.documents_list_versions(config, document)
# res_filtered = [{key: r[key] for key in list(VersionLog.__fields__.keys())} for r in res]
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment

@router.post("/db/{nsname}/", tags=[Tags.db])
async def ns_resource_post(nsname: str, db: DB, request: Request):
"""Create a non-existing namespace from data"""
_db = await request.json()
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like db is not in use?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for methods below

@tzuryby tzuryby merged commit 52fb0a0 into main Mar 7, 2023
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.

None yet

3 participants