Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix #540 #246

Merged
merged 3 commits into from
Jul 11, 2024
Merged

fix #540 #246

merged 3 commits into from
Jul 11, 2024

Conversation

Horiodino
Copy link
Contributor

@Horiodino Horiodino commented Jun 11, 2024

Please specify the area for this PR

What does does this PR do / why we need it:

Which issue(s) this PR fixes:

Fixes #devfile/api#540

PR acceptance criteria:

  • Test Coverage
    • Are your changes sufficiently tested, and are any applicable test cases added or updated to cover your changes?

Documentation (WIP)

How to test changes / Special notes to the reviewer:

Signed-off-by: Horiodino <holiodin@gmail.com>
@Jdubrick
Copy link
Contributor

/ok-to-test

@Jdubrick
Copy link
Contributor

All the checks pass in our CI - Are you still experiencing issues building locally @Horiodino

fyi @michael-valdron

@Horiodino
Copy link
Contributor Author

is the code working as expected ?

@Horiodino
Copy link
Contributor Author

yep i can build image and test case is running!

@Jdubrick
Copy link
Contributor

yep i can build image and test case is running!

No issues locally anymore? @Horiodino

@Horiodino
Copy link
Contributor Author

nope

@@ -543,6 +543,12 @@ func buildIndexAPIResponse(c *gin.Context, indexType string, wantV1Index bool, p
if params.Deprecated != nil {
util.FilterDevfileDeprecated(&index, *params.Deprecated, wantV1Index)
}
if index == nil || len(index) == 0 {
c.JSON(http.StatusOK, gin.H{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c.JSON(http.StatusOK, gin.H{
c.JSON(http.StatusInternalServerError, gin.H{

I'm wondering if this should be a 500 instead of a 200 as it not having the samples is technically an error and is referenced as an error in the original issue

https://go.dev/src/net/http/status.go

wdyt @michael-valdron

Copy link
Member

Choose a reason for hiding this comment

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

@Jdubrick Maybe 404 would be more appropriate error code here, since no stacks or samples can be found.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking 500 as it would be the servers fault no samples were loaded, no? I am also okay with 404 though

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking 500 as it would be the servers fault no samples were loaded, no? I am also okay with 404 though

That is a good point, but in this case the control logic that provides this response does not guarantee that the stacks and samples are not loaded due to error versus just having an empty registry.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with 404 in that case.

@Horiodino for reference that is http.StatusNotFound

Copy link
Member

Choose a reason for hiding this comment

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

IMO, in a world where we're working towards more dynamic devfile registries, I'd argue that a 200 code is fine here.

@@ -543,6 +543,12 @@ func buildIndexAPIResponse(c *gin.Context, indexType string, wantV1Index bool, p
if params.Deprecated != nil {
util.FilterDevfileDeprecated(&index, *params.Deprecated, wantV1Index)
}
if index == nil || len(index) == 0 {
c.JSON(http.StatusOK, gin.H{
"status": "No samples found in the registry",
Copy link
Member

Choose a reason for hiding this comment

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

Because this response is returned if index has no entries and not just the samples, the status should mention stacks too:

Suggested change
"status": "No samples found in the registry",
"status": "No stacks or samples found in the registry",

Signed-off-by: Horiodino <holiodin@gmail.com>
@@ -543,6 +543,12 @@ func buildIndexAPIResponse(c *gin.Context, indexType string, wantV1Index bool, p
if params.Deprecated != nil {
util.FilterDevfileDeprecated(&index, *params.Deprecated, wantV1Index)
}
if index == nil || len(index) == 0 {
c.JSON(http.StatusNotFound, gin.H{
Copy link
Member

Choose a reason for hiding this comment

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

TBH, I think this should actually be http.StatusOK.

@michael-valdron @Jdubrick It might be unusual to have a registry return no stacks, but IMO, I think 200 is more appropriate here than 404 or 500, especially as we work towards a more dynamic registry in devfile/api#1505

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm okay with reverting it back to a 200 response. @Horiodino feel free to revert that change

Signed-off-by: Horiodino <holiodin@gmail.com>
Copy link
Contributor

@Jdubrick Jdubrick left a comment

Choose a reason for hiding this comment

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

Tested locally - Removed extraDevfileEntries.yaml from the tests directory and created the registry. After hitting /index/sample I was able to receive the correct response.

@michael-valdron since you requested changes I'll wait until you take a look as well before merging

@openshift-ci openshift-ci bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jul 9, 2024
Copy link
Member

@michael-valdron michael-valdron left a comment

Choose a reason for hiding this comment

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

/lgtm

Tried locally with an empty index, works as expected in headless:

image

@devfile/devfile-services-team I noticed that when the index empty that the registry viewer is throwing errors:

TypeError: devfileJsons[devfileRegistryIndex].map is not a function
    at /app/apps/registry-viewer/dist/.next/server/chunks/951.js:5066:110
    at Array.flatMap (<anonymous>)
    at fetchDevfiles (/app/apps/registry-viewer/dist/.next/server/chunks/951.js:5066:33)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getServerSideProps (/app/apps/registry-viewer/dist/.next/server/pages/index.js:205:25)
    at async Object.renderToHTML (/app/node_modules/next/dist/server/render.js:507:20)
    at async doRender (/app/node_modules/next/dist/server/base-server.js:720:34)
    at async cacheEntry.responseCache.get.incrementalCache.incrementalCache (/app/node_modules/next/dist/server/base-server.js:837:28)
    at async /app/node_modules/next/dist/server/response-cache/index.js:83:36

If we are expecting a devfile registry to have a case with an empty index, there should be a follow issue created to address this on the registry viewer.

Copy link

openshift-ci bot commented Jul 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Horiodino, Jdubrick, michael-valdron

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Jdubrick,michael-valdron]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@michael-valdron
Copy link
Member

@Horiodino Changes looks good and merging this now, thanks for your contribution towards this!

@michael-valdron michael-valdron merged commit 4e34d7d into devfile:main Jul 11, 2024
8 checks passed
@Horiodino
Copy link
Contributor Author

@Horiodino Changes looks good and merging this now, thanks for your contribution towards this!

🙌 Looking forward to working more , thanks

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants