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

Implement finch tracker #732

Merged
merged 93 commits into from
Sep 26, 2023
Merged

Implement finch tracker #732

merged 93 commits into from
Sep 26, 2023

Conversation

atuchin-m
Copy link
Collaborator

@atuchin-m atuchin-m commented Aug 30, 2023

For #741
Specs: https://docs.google.com/document/d/1hRWkAnJtPjyvFglUQE0GegtyNtcVkjFpHPssdJJAqN0/

Ready to review.

TODO:

  • change private repo URL
  • change slack group ID for notifications
  • deploy new griffin.brave.com after the PR is merged

@atuchin-m atuchin-m self-assigned this Aug 30, 2023
@socket-security
Copy link

socket-security bot commented Aug 30, 2023

@atuchin-m atuchin-m marked this pull request as ready for review September 1, 2023 13:02
src/core/blocklists.ts Show resolved Hide resolved
src/core/blocklists.ts Show resolved Hide resolved
src/finch_tracker/node_utils.ts Show resolved Hide resolved
src/finch_tracker/node_utils.ts Show resolved Hide resolved
src/core/study_processor.ts Outdated Show resolved Hide resolved
src/core/version.ts Outdated Show resolved Hide resolved
src/web/src/app.tsx Outdated Show resolved Hide resolved
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

This is great and I only have minimal feedback. I haven't run it with data yet because I don't know the params to give to npm run tracker. Could you provide them please and I'll look more at the UI?

In the meantime, if you want to use less CSS, less bootstrap and more Brave UI style, you might benefit from using the design system which exports react UI Components as well as css variables for colors / fonts / effects. The repo is at https://github.com/brave/leo and preview of all the components is at https://leo.bravesoftware.com/. You could simply use the Button, Toggle and Input components, if helpful.

@@ -0,0 +1,88 @@
// Copyright (c) 2023 The Brave Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

nit: instead of using a utils file, consider either splitting to more specific-named files or perhaps even recognising that these are all similarly related and perhaps calling this config_params.ts or maybe just params.ts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, split the file.

src/core/study_processor.ts Outdated Show resolved Hide resolved
src/finch_tracker/finch_tracker_main.ts Outdated Show resolved Hide resolved

export function getStudyPath(storageDir: string): string {
return path.join(storageDir, 'study');
}
Copy link
Member

Choose a reason for hiding this comment

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

does getSeedPath and getStudyPath belong in your (currently named) core_utils file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They are only for tracker, not relevant for web/core code.

src/web/src/app.tsx Outdated Show resolved Hide resolved
src/web/src/models.ts Outdated Show resolved Hide resolved
src/web/src/models.ts Outdated Show resolved Hide resolved
.get(currentSeed)
?.studies(filter)
.map((study, i) => (
<StudyItem key={study.name() + i} study={study} filter={filter} />
Copy link
Member

Choose a reason for hiding this comment

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

If study.name is guaranteed to be unique, then it's not best practice to use i in the key as the re-use of elements won't be as optimized. But if items never get added or removed then it's irrelevant anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sadly, study.name is not unique. There is not good key for the list.
Also, we load the lists once, so we could use index & seedType as key.

src/web/src/app.tsx Outdated Show resolved Hide resolved
Comment on lines 285 to 287
const studyList = props.studies
.get(currentSeed)
?.studies(filter)
Copy link
Member

Choose a reason for hiding this comment

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

This should also be memoized if we're going to memoize in our children, in order to make sure each study object is ===.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done. Could you take a look?
I have a doubt that useMemo() work well for filter object that recreated each time we render.
Check in devtools that it's not a hot path.

@petemill
Copy link
Member

I also created this PR based on this branch which starts webpack's dev web server and enables hot reloading of the UI. Also moves typescript compilation for the web project to webpack. #744

@atuchin-m
Copy link
Collaborator Author

atuchin-m commented Sep 14, 2023

This is great and I only have minimal feedback. I haven't run it with data yet because I don't know the params to give to npm run tracker. Could you provide them please and I'll look more at the UI?

Thanks for the feedback, @petemill.
To run the frontend: npm run build in 'srcthenpython3 -m http.serverinsrc/webAlso there is some issue with API access from localhost. Useuse-local-apibranch in this repo to bypass. To run the CI job usenpm run tracker -- /tmp/somedir`. Also https://github.com/brave/finch-data-private/blob/main/.github/workflows/finch-tracker.yml

In the meantime, if you want to use less CSS, less bootstrap and more Brave UI style, you might benefit from using the design system which exports react UI Components as well as css variables for colors / fonts / effects. The repo is at https://github.com/brave/leo and preview of all the components is at https://leo.bravesoftware.com/. You could simply use the Button, Toggle and Input components, if helpful.

Thanks, I will take a look. The idea to reuse leo repo sounds good to me. Although, the main purpose of this PR is to start collecting Finch data to the private repo and send notifications. So maybe we need another iteration for that.

className={props.className}
target="blank"
rel="noreferrer"
href={props.feature.link}
Copy link
Contributor

Choose a reason for hiding this comment

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

reported by reviewdog 🐶
[semgrep] Detected a variable used in an anchor tag with the 'href' attribute. A malicious actor may be able to input the 'javascript:' URI, which could cause cross-site scripting (XSS). It is recommended to disallow 'javascript:' URIs within your application.

Source: https://semgrep.dev/r/typescript.react.security.audit.react-href-var.react-href-var


Cc @thypon @bcaller

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fact, this could be only https:// URL. How to fix the warning?

Copy link
Member

Choose a reason for hiding this comment

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

function sanitizeUrl(url) {
    try {
        const ALLOWED_PROTOCOLS = ['http:', 'https:'];
        const trimmedUrl = url.trim();
        return ALLOWED_PROTOCOLS.includes(new URL(trimmedUrl, document.baseURI).protocol) ? trimmedUrl : '#';
    } catch(err) {
        return '#';
    }
}

Wrapping the link in a sanitizeUrl should do the trick, here

@atuchin-m
Copy link
Collaborator Author

@thypon Anything from your side? The files were moved a bit.

src/web/app/app.tsx Outdated Show resolved Hide resolved
src/web/app/app.tsx Outdated Show resolved Hide resolved
src/web/app/app.tsx Outdated Show resolved Hide resolved
src/web/app/seed_loader.ts Outdated Show resolved Hide resolved
src/web/app/seed_loader.ts Outdated Show resolved Hide resolved
Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Nice. Just a couple minor suggestions that are up to you!

petemill

This comment was marked as duplicate.

className={props.className}
target="blank"
rel="noreferrer"
href={props.feature.link}
Copy link
Member

Choose a reason for hiding this comment

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

function sanitizeUrl(url) {
    try {
        const ALLOWED_PROTOCOLS = ['http:', 'https:'];
        const trimmedUrl = url.trim();
        return ALLOWED_PROTOCOLS.includes(new URL(trimmedUrl, document.baseURI).protocol) ? trimmedUrl : '#';
    } catch(err) {
        return '#';
    }
}

Wrapping the link in a sanitizeUrl should do the trick, here

src/web/app/app.tsx Outdated Show resolved Hide resolved
@atuchin-m atuchin-m merged commit 30f5653 into main Sep 26, 2023
5 checks passed
@atuchin-m atuchin-m deleted the implement-finch-tracker branch September 26, 2023 11:19
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.

5 participants