-
Notifications
You must be signed in to change notification settings - Fork 108
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
UI to interact with Relay server #3484
UI to interact with Relay server #3484
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great; you seem to have some duplicate code to clean up, plus we need to finalize the header in the dialog.
uri: fileURI, | ||
}); | ||
const response = await API.post(uri, null, null); | ||
if (response.status >= 200 && response.status < 300) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's interesting. Does that mean that the axios response
object doesn't have an ok
attribute or method? Too bad.
This is probably fine, although the server will only return 201 (CREATED
) or 200 (OK
) on success. But anything else will be >= 400, so this will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In axios, there is ok
attribute in the response object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you didn't use if (response.ok)
here, then? It's not a problem, and I think this will work just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work just fine.
Yes, but ok
would be better.... 🙂
uri: fileURI, | ||
}); | ||
const response = await API.post(uri, null, null); | ||
if (response.status >= 200 && response.status < 300) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you didn't use if (response.ok)
here, then? It's not a problem, and I think this will work just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good (and so I'm approving), but I've pointed out some opportunities for polishing if you feel inclined.
}; | ||
const handleClose = () => { | ||
dispatch(handleInputChange("")); | ||
dispatch(toggleRelayModal(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a huge deal, but I think that toggleRelayModal()
is misnamed -- "toggle" generally refers to inverting an existing state, like switching from "true" to "false" and "false" to "true", and, therefore, a toggle function would not require an parameter, because its behavior would be based on the existing state -- so this function really should be named something more like "setRelayModalState()".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the function
const pullServerData = () => { | ||
dispatch(uploadFile()); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not obvious what the benefit of wrapping this dispatch()
call in a function is. I would in-line its body in the place where it is called and omit this definition (like what you did at line 97). Failing that, you know my bias toward expressions, so, if you don't in-line it, I would express this as:
const pullServerData = () => dispatch(uploadFile());
which is simpler here, but I don't know if it will make a difference at the invocation site (i.e., my code would evaluate to a Promise
while I think yours throws away the Promise and evaluates to undefined
).
<p> | ||
When a firewall prevents this direct access, the Pbench Agent can store a | ||
dataset tarball and a manifest file on a file relay server which can be | ||
reached by both the Pbench Agent and the Pbench Server.{" "} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want or need the trailing {" "}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it
Enter the relay server URI reported by the Pbench Agent and press Submit | ||
to begin the import. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we like "import"? I would recommend "upload". 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced
const PopoverComponent = () => { | ||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a code blob which does nothing but invoke a return
statement is pointless -- just remove the brances and the return
statement and let the expression to be returned stand as the value of the arrow function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
const uri = uriTemplate(endpoints, "relay", { | ||
uri: fileURI, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you remove the trailing comma from line 16, I bet Prettier will combine these three lines into one, which would be nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha
uri: fileURI, | ||
}); | ||
const response = await API.post(uri, null, null); | ||
if (response.status >= 200 && response.status < 300) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will work just fine.
Yes, but ok
would be better.... 🙂
if (response.status === 201) { | ||
// need to remove once response returns the uploaded dataset | ||
dispatch(getDatasets()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the code comment at line 24. (Should this instead be applied to line 21, which removes the modal dialog display?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MVarshini : despite this comment, it's probably best to leave the code alone for now and come back later.
However, for what it's worth, if you want to think about your refresh optimization ideas, I've updated the staging server with the latest code from main
. I restarted the relay and pushed a dataset, and now (omitting the internal hostnames from GitHub comments):
POST https://<staging-server>/api/v1/relay/http://<relay>:8002/RELAY/4bcada96aff3b1d9a62540962204c833c12cd9266b10d747e1ef71b278d23a09
will return:
{
"message": "File successfully uploaded",
"name": "pbench-user-benchmark_newrelay_2023.07.11T12.04.37",
"resource_id": "a9b1daaa5549c4063c00e1d62115c9e5"
}
); | ||
dispatch({ type: TYPES.NETWORK_ERROR }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the NETWORK_ERROR
action do? (I don't see a reducer which actually handles it.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand that, either: I haven't noticed anything that sets a payload
value, but the actions here and in the visualizer PR both use this unconditionally when errors occur, but I don't see any implementation of that type code.
Create UItointeract with relay server pull API
if (response.status === 201) { | ||
// need to remove once response returns the uploaded dataset | ||
dispatch(getDatasets()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MVarshini : despite this comment, it's probably best to leave the code alone for now and come back later.
However, for what it's worth, if you want to think about your refresh optimization ideas, I've updated the staging server with the latest code from main
. I restarted the relay and pushed a dataset, and now (omitting the internal hostnames from GitHub comments):
POST https://<staging-server>/api/v1/relay/http://<relay>:8002/RELAY/4bcada96aff3b1d9a62540962204c833c12cd9266b10d747e1ef71b278d23a09
will return:
{
"message": "File successfully uploaded",
"name": "pbench-user-benchmark_newrelay_2023.07.11T12.04.37",
"resource_id": "a9b1daaa5549c4063c00e1d62115c9e5"
}
); | ||
dispatch({ type: TYPES.NETWORK_ERROR }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand that, either: I haven't noticed anything that sets a payload
value, but the actions here and in the visualizer PR both use this unconditionally when errors occur, but I don't see any implementation of that type code.
PBENCH-1141
Develop UI to interact with Relay server 'pull' API