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

AJ-1371: link snapshots during AnVIL pfb import #386

Merged
merged 21 commits into from
Oct 30, 2023

Conversation

davidangb
Copy link
Collaborator

@davidangb davidangb commented Oct 27, 2023

When importing a PFB:

  • query WSM to find all pre-existing snapshot references for this workspace. This is a paginated query so it requires some extra logic.
  • compare the list of snapshot ids mentioned in the pfb to the list of pre-existing snapshots, and identify the list of not-yet-linked snapshots
  • create references from the workspace to those new snapshots

@davidangb davidangb marked this pull request as ready for review October 27, 2023 20:12
}
}

private UUID maybeUuid(String input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly a place for an Optional instead of a null? (disclosure: I generally steer clear of nulls in Java if possible)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm gonna push back here - I think that's sound advice to use Optional instead of null for public methods, but this is a private method used only within the class. If it returned Optional, it would require additional steps inside of executeInternal(). Whereas now we can use one step .filter(Objects::nonNull), we'd need to change to .filter(Optional::isPresent).map(Optional::get).

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds fine, particularly making the distinction between public and private APIs. I have a hunch that there'd be some optional-friendly predicate that could stand in for (and have equivalent terseness to) what's already there, but don't know off the top of my head what it'd be so carry on!

PfbQuartzJobSupport pfbQuartzJobSupport =
new PfbQuartzJobSupport(workspaceId, wsmDao, restClientRetry);
List<UUID> existingSnapshotIds =
pfbQuartzJobSupport.existingPolicySnapshotIds(/* pageSize= */ 50);
Copy link
Contributor

@jladieu jladieu Oct 30, 2023

Choose a reason for hiding this comment

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

Thanks for the arg comment ❤️

}
}
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Another possible place for an Optional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same pushback here - as a non-public method (it's only protected instead of private so I can unit-test it), I'm optimizing for performance instead of a good API - this one is also used directly as a stream mapping function

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
Copy link
Contributor

Choose a reason for hiding this comment

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

The way PfbImportException gets thrown (for blowing the hard limit), and the fact that it subclasses IllegalArgumentException make it seem more like some kind of client error than an internal error to me. Should this be a different HTTP status?

That said, I think we'd want to know about these early on as we learn how this feature gets used, so if it makes more sense that it's an 'us' problem than a client problem, then you can keep it as INTERNAL_SERVER_ERROR...I just wonder if it should subclass a different kind of exception in that case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The use of IllegalArgumentException here was a copy/paste mistake on my part, I have changed to extend RuntimeException!

I do consider this an "us" problem. Even though I think it highly unlikely that a workspace will have > 10000 snapshot references, it's our fault that we can't handle such a case, so I agree on keeping it as INTERNAL_SERVER_ERROR.

fwiw, I originally wrote the loop inside listAllSnapshots as a while(true) loop, but I got nervous about infinity and decided to add a sanity check and thus imposed a hard limit.

}
}

throw new PfbImportException(
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 sensible way to fail faster if we'll exceed the hard limit? Maybe by pushing the hard limit enforcement down to WSM?

Feels like this approach ends up doing a whole bunch of wasted work and would potentially fail slowly and cause resource waste/exhaustion when paired with some form of retries.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The only other approach I can think of is to pick a number (maybe not as high as 10000), and make a single request to WSM for that many resources - don't attempt to paginate. Do you think that would be better?

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 if by your guess this is a really really unlikely scenario that it's maybe not something to worry about and this might be the perfect safeguard...wait till it happens, then worry about it.

I don't think I understand well enough how these snapshots get written to WSM, but the only thing that I think might be better is if we could somehow head them off at write time (into WSM) rather than here at read time.

Copy link
Contributor

@jladieu jladieu left a comment

Choose a reason for hiding this comment

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

I had a few style questions and one more involved thought about how to deal with the hard limit enforcement. But LGTM overall!

@sonarcloud
Copy link

sonarcloud bot commented Oct 30, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

79.3% 79.3% Coverage
0.0% 0.0% Duplication

@davidangb davidangb merged commit afcedac into main Oct 30, 2023
12 checks passed
@davidangb davidangb deleted the da_AJ-1371_snapshotLinking branch October 30, 2023 19:37
@davidangb davidangb mentioned this pull request Oct 31, 2023
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.

4 participants