Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
k8s-api-balancer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DMIR
k8s-api-balancer
Commits
7f957236
Commit
7f957236
authored
3 weeks ago
by
zehe
Browse files
Options
Downloads
Patches
Plain Diff
cleanup
parent
c79eb420
Branches
main
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/api-balancer.py
+0
-64
0 additions, 64 deletions
app/api-balancer.py
with
0 additions
and
64 deletions
app/api-balancer.py
+
0
−
64
View file @
7f957236
...
@@ -165,70 +165,6 @@ async def startup_event():
...
@@ -165,70 +165,6 @@ async def startup_event():
asyncio
.
create_task
(
update_api_pods
())
asyncio
.
create_task
(
update_api_pods
())
class
Document
(
BaseModel
):
text
:
str
"""
@app.post(
"
/kallimachosPipeline
"
)
async def process_document(request: Request):
logger.info(f
"
Received request
"
)
# Read the body as raw bytes
raw_body = await request.body()
# First, try to parse as JSON.
try:
body = json.loads(raw_body)
except json.JSONDecodeError:
# If JSON decoding fails, try to parse as URL-encoded data.
qs = raw_body.decode(
"
utf-8
"
)
parsed_qs = urllib.parse.parse_qs(qs)
# parse_qs returns a dict with list values; extract the first item.
body = {k: v[0] for k, v in parsed_qs.items() if v}
text = body.get(
"
text
"
)
if not text:
return {
"
error
"
:
"
Missing
'
text
'
in request body.
"
}
# Wait until one pod is available.
pod_ip, pod_name = await get_free_pod()
logger.info(f
"
Selected pod: {pod_ip, pod_name}
"
)
await asyncio.sleep(10)
try:
# Prepare the file to send to the API pod.
# We assume the API pod is listening on port 80.
url = f
"
http://{pod_ip}:80/kallimachosPipeline
"
myobj = {
'
text
'
: text}
headers = {
'
Content-type
'
:
'
application/json; charset=utf-8
'
}
async with httpx.AsyncClient(timeout=None) as client:
response = await client.post(url, data=myobj, headers=headers)
if response.status_code != 200:
raise HTTPException(
status_code=response.status_code,
detail=f
"
Error from upstream API pod: {response.text}
"
)
# Optionally, pass through relevant headers (adjust as needed)
headers = {
key: value
for key, value in response.headers.items()
if key.lower() in [
"
content-type
"
,
"
content-disposition
"
]
}
return Response(
content=response.content,
status_code=response.status_code,
headers=headers
)
except Exception as err:
raise HTTPException(status_code=500, detail=str(err))
finally:
await mark_pod_free(pod_ip, pod_name)
"""
@app.api_route
(
"
/{path:path}
"
,
methods
=
[
"
GET
"
,
"
POST
"
,
"
PUT
"
,
"
PATCH
"
,
"
DELETE
"
,
"
OPTIONS
"
,
"
HEAD
"
])
@app.api_route
(
"
/{path:path}
"
,
methods
=
[
"
GET
"
,
"
POST
"
,
"
PUT
"
,
"
PATCH
"
,
"
DELETE
"
,
"
OPTIONS
"
,
"
HEAD
"
])
async
def
proxy
(
path
:
str
,
request
:
Request
):
async
def
proxy
(
path
:
str
,
request
:
Request
):
logger
=
app
.
logger
if
hasattr
(
app
,
"
logger
"
)
else
print
logger
=
app
.
logger
if
hasattr
(
app
,
"
logger
"
)
else
print
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment