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

Hide overrides key if empty, display comment for flags if empty #7986

Merged
merged 5 commits into from
Oct 4, 2022

Conversation

mna
Copy link
Member

@mna mna commented Sep 27, 2022

#7377 (frontend portion)

NOTE: This builds on top of #7979 (contains commits of both). This one is for the frontend only, and to see the diff just for this PR, see here: mna-7377-agent-options-cliflags-2...mna-7377-agent-options-cliflags-3-frontend

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Manual QA for all new/changed functionality

Sorry, something went wrong.

@mna mna changed the base branch from mna-7377-agent-options-cliflags-2 to main September 27, 2022 20:28
@mna mna temporarily deployed to Docker Hub September 27, 2022 20:36 Inactive
@cypress
Copy link

cypress bot commented Sep 27, 2022



Test summary

208 0 0 0Flakiness 0


Run details

Project Fleet
Status Passed
Commit c2e90c12a5 ℹ️
Started Oct 3, 2022 1:28 PM
Ended Oct 3, 2022 1:45 PM
Duration 17:22 💡
OS Linux Ubuntu - 20.04
Browser Electron 94

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

Copy link
Member Author

@mna mna left a comment

Choose a reason for hiding this comment

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

Hey frontend reviewers 👋 This is my first frontend PR with significant-ish changes, so let me know if I missed anything, especially regarding formatting/conventions/etc. The change seems to work well from manually playing with it locally, but if you feel it's missing anything or could be done a simpler/better way, please let me know, I'm not super familiar with typescript and react (nor with our frontend codebase and tooling!).

This PR is cut off from #7979 and includes those changes (as I had to target the main branch for CI to work properly), but to see just this PR's changes, you can click here: mna-7377-agent-options-cliflags-2...mna-7377-agent-options-cliflags-3-frontend

@@ -26,7 +26,7 @@ const Agents = ({
const { ADMIN_TEAMS } = paths;

const [formData, setFormData] = useState<any>({
agentOptions: yaml.dump(appConfig.agent_options) || {},
agentOptions: agentOptionsToYaml(appConfig.agent_options) || {},
Copy link
Member Author

Choose a reason for hiding this comment

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

I just modified the code that was already there, but shouldn't the || {} be inside the parens? I.e. to yaml-encode an empty object if appConfig.agent_options is null/undefined? Because yaml.dump returns a string, it seems weird to me to change an empty string to an object if the string is empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right, moreover, agentOptions is being assigned to a string below, so it doesn't make sense to assign an object here.

A fun fact about the JS ecosystem (but I don't think it applies here): many libraries have their type definitions separated from their source code, so you can't fully trust them, the return type might say string, but the actual behavior of the library might be undefined (for example) so a case like this one might be intentional

@@ -43,7 +43,7 @@ const AgentOptionsPage = ({

if (selected) {
setFormData({
osquery_options: yaml.dump(selected.agent_options),
osquery_options: agentOptionsToYaml(selected.agent_options),
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we have the same || {} (presumably inside the parens) here too?

Copy link
Contributor

Choose a reason for hiding this comment

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

if yaml.dump gracefully handles falsey values, I'd be inclined to just leave it like this. Otherwise yes, I vote to add the safety || {}

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up moving the check inside agentOptionsToYaml instead.

@@ -200,6 +200,7 @@ export const formatConfigDataForServer = (config: any): any => {
};

// TODO: Finalize interface for config - see frontend\interfaces\config.ts
// TODO(mna): this appears to be unused?
Copy link
Member Author

Choose a reason for hiding this comment

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

If we're unsure I can just remove my comment. Never seems to be called from a code search but there may be more to it to be sure.

Copy link
Contributor

Choose a reason for hiding this comment

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

i'd say remove it. I dont see any use of it in the codebase

@mna mna marked this pull request as ready for review September 27, 2022 21:07
@mna mna requested review from ksatter, chris-mcgillicuddy and a team as code owners September 27, 2022 21:07
@mna mna temporarily deployed to Docker Hub September 28, 2022 12:32 Inactive
roperzh
roperzh previously approved these changes Sep 28, 2022
Copy link
Contributor

@roperzh roperzh left a comment

Choose a reason for hiding this comment

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

LGTM, super cool way of handling things. I left a couple of questions

return `${yamlError.name}: ${yamlError.reason} at line ${yamlError.line}`;
};

export const agentOptionsToYaml = (agentOpts: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

is there any chance of agentOpts being undefined or null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently this was done (or meant to be done, I guess) at the callsite with the || {} but you're right, maybe it should be done here inside this function instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

we dont have the best typing in some parts of the app atm. I'd look at where this code is used to determine if that's a possiblity.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the check inside the func. Regarding the type, agent_options is not strictly defined even on the backend, it can have arbitrary keys as those are passed to the osquery agent ultimately, so I left it as any.

@@ -43,7 +43,7 @@ const AgentOptionsPage = ({

if (selected) {
setFormData({
osquery_options: yaml.dump(selected.agent_options),
osquery_options: agentOptionsToYaml(selected.agent_options),
Copy link
Contributor

Choose a reason for hiding this comment

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

if yaml.dump gracefully handles falsey values, I'd be inclined to just leave it like this. Otherwise yes, I vote to add the safety || {}

@roperzh roperzh requested a review from a team September 28, 2022 14:18
@mna mna force-pushed the mna-7377-agent-options-cliflags-3-frontend branch from 76f1e5f to a668bac Compare September 28, 2022 18:40
@mna mna temporarily deployed to Docker Hub September 28, 2022 18:40 Inactive
ghernandez345
ghernandez345 previously approved these changes Sep 29, 2022
Copy link
Contributor

@ghernandez345 ghernandez345 left a comment

Choose a reason for hiding this comment

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

FE bit looks good

@@ -200,6 +200,7 @@ export const formatConfigDataForServer = (config: any): any => {
};

// TODO: Finalize interface for config - see frontend\interfaces\config.ts
// TODO(mna): this appears to be unused?
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd say remove it. I dont see any use of it in the codebase

return `${yamlError.name}: ${yamlError.reason} at line ${yamlError.line}`;
};

export const agentOptionsToYaml = (agentOpts: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

we dont have the best typing in some parts of the app atm. I'd look at where this code is used to determine if that's a possiblity.

@mna mna force-pushed the mna-7377-agent-options-cliflags-3-frontend branch from a668bac to 4ded49f Compare October 3, 2022 12:42
@mna mna temporarily deployed to Docker Hub October 3, 2022 12:42 Inactive
@mna mna temporarily deployed to Docker Hub October 3, 2022 13:21 Inactive
@mna mna requested review from roperzh and ghernandez345 October 3, 2022 13:54
@chris-mcgillicuddy
Copy link
Contributor

@gillespi314, could you please review these code changes?

Copy link
Contributor

@chris-mcgillicuddy chris-mcgillicuddy left a comment

Choose a reason for hiding this comment

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

Since there are no copy changes, I asked the on-call engineer to review the code.

@mna mna merged commit f5b6523 into main Oct 4, 2022
@mna mna deleted the mna-7377-agent-options-cliflags-3-frontend branch October 4, 2022 12:40
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

4 participants