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

feat: API for Tags #237

Merged
merged 6 commits into from
Jan 19, 2024
Merged

feat: API for Tags #237

merged 6 commits into from
Jan 19, 2024

Conversation

svc-shorpo
Copy link
Contributor

No description provided.

Copy link

changeset-bot bot commented Jan 14, 2024

🦋 Changeset detected

Latest commit: 86649d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@hyperdx/api Patch
@hyperdx/app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

query: `${query}`,
team: teamId,
creator: userId,
}).save();

if (tags?.length) {
redisClient.del(`tags:${teamId}`).catch(e => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can also move this to mongoose post hook on Dashboard and LogView 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

my 2c is that we should avoid caching complexity until it's warranted. I think for now avoiding caching and just reading directly from mongo would be perfect. Usually just long CH-operations warrant caching (and even then I try to push for cache-less approaches)

Though @wrn14897 maintains the backend so I'll defer to his final judgement :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense! removed caching and used aggregation to get all tags for a team

Copy link
Contributor

Choose a reason for hiding this comment

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

agreed that we should remove the caching for now unless it has a dramatic performance impact

@svc-shorpo svc-shorpo marked this pull request as ready for review January 14, 2024 22:43
ms('10m'),
async () => {
const _tags: string[] = [];
const dashboards = await Dashboard.find(
Copy link
Contributor

Choose a reason for hiding this comment

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

We've gotten a bit loose with our standards recently, but our preference is actually that mongoose code lives under a controller, maybe under the controllers/team.ts in this case - so that we can encapsulate data fetching separate from router logic. I know that several of our routes don't do this but we've recently talked about trying to get back on track again :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

Comment on lines 38 to 48
const dashboardTags = await Dashboard.aggregate([
{ $match: { team: teamId } },
{ $unwind: '$tags' },
{ $group: { _id: '$tags' } },
]);

const logViewTags = await LogView.aggregate([
{ $match: { team: teamId } },
{ $unwind: '$tags' },
{ $group: { _id: '$tags' } },
]);
Copy link
Contributor

Choose a reason for hiding this comment

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

we can fetch these concurrently

@@ -106,15 +107,15 @@ router.post(
return res.sendStatus(403);
}

const { name, charts, query } = req.body ?? {};
const { name, charts, query, tags } = req.body ?? {};
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to assert the uniqueness of tagging values and also enforce the size limit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, added uniq(). by size limit do you mean array length or individual tag lengths?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think we should enforce the limit on both lengths tho (zod validator). like individual tag length 32 and array length 50

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added it for dashboards endpoint. since logViews doesn't have validators, think it'll be better to address it in a separate PR. will add a task

// Create new dashboard from name and charts
const newDashboard = await new Dashboard({
name,
charts,
query,
tags,
tags: tags && uniq(tags),
Copy link
Contributor

Choose a reason for hiding this comment

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

double check that we want to assign this undefined instead empty array ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, just want to skip updating this field if it's not passed. just in case we run old app and new api at the same time, to prevent data loss

Copy link
Contributor

@wrn14897 wrn14897 left a comment

Choose a reason for hiding this comment

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

lgtm

@kodiakhq kodiakhq bot merged commit f10c3be into main Jan 19, 2024
4 checks passed
@kodiakhq kodiakhq bot deleted the sr/tags-api branch January 19, 2024 05:34
@svc-shorpo svc-shorpo mentioned this pull request Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants