Skip to content

Commit

Permalink
example responses
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Jan 9, 2025
1 parent 9e588b9 commit eaebe65
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 40 deletions.
33 changes: 33 additions & 0 deletions backend/app/api/v1/commons/example_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def telco_200_response():
return response_200(telco_response_example)


def ocp_filter_200_response():
return response_200(ocp_filter_example)


def quay_filter_200_response():
return response_200(quay_filter_example)


cpt_response_example = {
"startDate": "2023-11-18",
"endDate": "2023-11-23",
Expand Down Expand Up @@ -191,6 +199,31 @@ def telco_200_response():
],
}

ocp_filter_example = {
"filterData": [
{"key": "jobStatus", "value": ["success", "failure"]},
{"key": "workerNodesCount", "value": [24, 6, 9, 3, 120, 249, 252, 25, 4, 240]},
{"key": "jobType", "value": ["pull-request", "periodic"]},
{"key": "isRehearse", "value": ["True", "False"]},
{"key": "networkType", "value": ["OVNKubernetes", "OpenShiftSDN"]},
],
"summary": {"total": 259, "success": 254, "failure": 5},
}

quay_filter_example = {
"filterData": [
{"key": "jobStatus", "value": ["success", "failure"]},
{"key": "workerNodesCount", "value": [24]},
{"key": "platform", "value": ["AWS"]},
{"key": "benchmark", "value": ["quay-load-test"]},
{
"key": "build",
"value": ["2024-10-12-102620"],
},
],
"summary": {"total": 3, "success": 3},
}


def cpt_200_response():
return response_200(cpt_response_example)
4 changes: 1 addition & 3 deletions backend/app/api/v1/commons/quay.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ async def getData(

cleanJobs = jobs[jobs["platform"] != ""]

jbs = cleanJobs

return {"data": jbs, "total": response["total"]}
return {"data": cleanJobs, "total": response["total"]}


async def getFilterData(start_datetime: date, end_datetime: date, configpath: str):
Expand Down
17 changes: 0 additions & 17 deletions backend/app/api/v1/commons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,6 @@ def getBuild(job):


def getReleaseStream(row):
# if row["releaseStream"].__contains__("fast"):
# return "Fast"
# elif row["releaseStream"].__contains__("stable"):
# return "Stable"
# elif row["releaseStream"].__contains__("eus"):
# return "EUS"
# elif row["releaseStream"].__contains__("candidate"):
# return "Release Candidate"
# elif row["releaseStream"].__contains__("rc"):
# return "Release Candidate"
# elif row["releaseStream"].__contains__("nightly"):
# return "Nightly"
# elif row["releaseStream"].__contains__("ci"):
# return "ci"
# elif row["releaseStream"].__contains__("ec"):
# return "Engineering Candidate"
# return "Stable"
releaseStream = next(
(
value
Expand Down
12 changes: 8 additions & 4 deletions backend/app/api/v1/endpoints/ocp/ocpJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from datetime import datetime, timedelta, date
from fastapi import APIRouter, HTTPException
from ...commons.ocp import getData, getFilterData
from ...commons.example_responses import ocp_200_response, response_422
from ...commons.example_responses import (
ocp_200_response,
response_422,
ocp_filter_200_response,
)
from fastapi.param_functions import Query

router = APIRouter()
Expand Down Expand Up @@ -85,13 +89,13 @@ async def jobs(

@router.get(
"/api/v1/ocp/filters",
summary="Returns a job list",
description="Returns a list of jobs in the specified dates. \
summary="Returns the data to construct filters",
description="Returns the data to build filters in the specified dates. \
If not dates are provided the API will default the values. \
`startDate`: will be set to the day of the request minus 5 days.\
`endDate`: will be set to the day of the request.",
responses={
200: ocp_200_response(),
200: ocp_filter_200_response(),
422: response_422(),
},
)
Expand Down
14 changes: 9 additions & 5 deletions backend/app/api/v1/endpoints/quay/quayJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from datetime import datetime, timedelta, date
from fastapi import APIRouter, HTTPException
from ...commons.quay import getData, getFilterData
from ...commons.example_responses import quay_200_response, response_422
from ...commons.example_responses import (
quay_200_response,
response_422,
quay_filter_200_response,
)
from fastapi.param_functions import Query

router = APIRouter()
Expand Down Expand Up @@ -72,8 +76,8 @@ async def jobs(
"startDate": start_date.__str__(),
"endDate": end_date.__str__(),
"results": jobs,
"total": 0,
"offset": 0,
"total": results["total"],
"offset": (offset + size) if size else 0,
}

if pretty:
Expand All @@ -86,13 +90,13 @@ async def jobs(

@router.get(
"/api/v1/quay/filters",
summary="Returns a filter list",
summary="Returns the data to construct filters",
description="Returns the data to build filters in the specified dates. \
If not dates are provided the API will default the values. \
`startDate`: will be set to the day of the request minus 5 days.\
`endDate`: will be set to the day of the request.",
responses={
200: quay_200_response(),
200: quay_filter_200_response(),
422: response_422(),
},
)
Expand Down
5 changes: 2 additions & 3 deletions backend/app/services/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def post(
self,
query,
indice=None,
size=None,
size=10000,
start_date=None,
end_date=None,
timestamp_field=None,
Expand Down Expand Up @@ -175,7 +175,6 @@ async def post(
query["query"]["bool"]["filter"]["range"][timestamp_field][
"lte"
] = str(end_date)

response = await self.new_es.search(
index=self.new_index + "*",
body=jsonable_encoder(query),
Expand Down Expand Up @@ -531,7 +530,7 @@ def buildReleaseStreamFilter(input_array):
"Stable",
)
mapped_array.append(match)
return mapped_array
return list(set(mapped_array))


def getBuildFilter(input_list):
Expand Down
6 changes: 0 additions & 6 deletions backend/app/services/splunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ async def query(
value = decoded_data.get("results")
total_records = value[0]["total_records"]

# Fetch the results
for result in job.results(output_mode="json"):
decoded_data = json.loads(result.decode("utf-8"))
value = decoded_data.get("results")
total_records = value[0]["total_records"]

# Get the results and display them using the JSONResultsReader
res_array = []
async for record in self._stream_results(oneshotsearch_results):
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/actions/ocpActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export const buildFilterData = () => async (dispatch, getState) => {

const params = dispatch(getRequestParams("ocp"));

const response = await API.get("/api/v1/ocp/filters", { params });
const response = await API.get(API_ROUTES.OCP_FILTERS_API_V1, { params });
if (response.status === 200 && response?.data?.filterData?.length > 0) {
let data = cloneDeep(response.data.filterData);
for (let i = 0; i < tableFilters.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/actions/quayActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export const buildFilterData = () => async (dispatch, getState) => {

const params = dispatch(getRequestParams("quay"));

const response = await API.get("/api/v1/quay/filters", { params });
const response = await API.get(API_ROUTES.QUAY_FILTERS_API_V1, { params });
if (response.status === 200 && response?.data?.filterData?.length > 0) {
let data = cloneDeep(response.data.filterData);
for (let i = 0; i < tableFilters.length; i++) {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/apiConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export const BASE_URL = getUrl();

export const OCP_JOBS_API_V1 = "/api/v1/ocp/jobs";
export const OCP_GRAPH_API_V1 = "/api/v1/ocp/graph";
export const OCP_FILTERS_API_V1 = "/api/v1/ocp/filters";

export const CPT_JOBS_API_V1 = "/api/v1/cpt/jobs";

export const QUAY_JOBS_API_V1 = "/api/v1/quay/jobs";
export const QUAY_GRAPH_API_V1 = "/api/v1/quay/graph";
export const QUAY_FILTERS_API_V1 = "/api/v1/quay/filters";

export const TELCO_JOBS_API_V1 = "/api/v1/telco/jobs";
export const TELCO_GRAPH_API_V1 = "/api/v1/telco/graph";

0 comments on commit eaebe65

Please sign in to comment.