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(config): Allow canary config id to be passed in instead of alway… #611

Merged
merged 1 commit into from
Sep 7, 2019

Conversation

duftler
Copy link
Collaborator

@duftler duftler commented Sep 6, 2019

…s randomly generated.

Copy link
Collaborator

@dotdotdotpaul dotdotdotpaul left a comment

Choose a reason for hiding this comment

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

I like.

@@ -39,6 +39,8 @@

@NotNull @Getter @Setter private String name;

@NotNull @Getter @Setter private String id;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Had to add id to canary config, and it will be populated anytime the config is persisted.

It still does not need to be provided on a POST or a PUT, so no changes are required to any dependent services.

Copy link

@jtk54 jtk54 left a comment

Choose a reason for hiding this comment

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

Few nits, LGTM. Thanks for the quick turnaround.

canaryConfigId = UUID.randomUUID() + "";

// Ensure that the canary config id is stored within the canary config itself.
if (StringUtils.isEmpty(canaryConfig.getId())) {
Copy link

Choose a reason for hiding this comment

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

This if seems unnecessary.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, copy/paste error.


// Ensure that the canary config id is stored within the canary config itself.
if (StringUtils.isEmpty(canaryConfig.getId())) {
canaryConfig = canaryConfig.toBuilder().id(canaryConfigId).build();
Copy link

Choose a reason for hiding this comment

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

Don't you have an @Setter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shouldn't, will remove it. Trying to stick to not modifying the instance once it's constructed.


// Ensure that the canary config id is stored within the canary config itself.
canaryConfig = canaryConfig.toBuilder().id(canaryConfigId).build();
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Probably just personal preference, but I think this would read easier if you removed the else block, so ti's more like

if (isEmpty(canaryConfig.getId())) {
  canaryConfig = canaryConfig.toBuilder().id(UUID.randomUUID().toString()).build();
}

String canaryConfigId = canaryConfig.getId();

Feel free to ignore if you disagree.

👍 to not modifying the object more than we already do... it's certainly surprising to pass an object to a store() method and find out the method secretly also modified it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That does read easier. Changed it.

@duftler
Copy link
Collaborator Author

duftler commented Sep 6, 2019

Copy link
Contributor

@csanden csanden left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -39,6 +39,8 @@

@NotNull @Getter @Setter private String name;

@NotNull @Getter private String id;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this field is not null, then you should populate this field on the GET requests to configs that already exist but do not yet have the id saved as part of the object.

@RequestMapping(value = "/{canaryConfigId:.+}", method = RequestMethod.GET)
public CanaryConfig loadCanaryConfig(
@RequestParam(required = false) final String configurationAccountName,
@PathVariable String canaryConfigId) {
String resolvedConfigurationAccountName =
CredentialsHelper.resolveAccountByNameOrType(
configurationAccountName,
AccountCredentials.Type.CONFIGURATION_STORE,
accountCredentialsRepository);
StorageService configurationService =
storageServiceRepository
.getOne(resolvedConfigurationAccountName)
.orElseThrow(
() ->
new IllegalArgumentException(
"No configuration service was configured; unable to read canary config from bucket."));
return configurationService.loadObject(
resolvedConfigurationAccountName, ObjectType.CANARY_CONFIG, canaryConfigId);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe this should be @nullable, so that way if JSR 308 validation is turned on people who don't supply an id, since it's technically optional won't get an API error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Have removed @NotNull.

@duftler duftler merged commit c29e8d9 into spinnaker:master Sep 7, 2019
@duftler duftler deleted the pass-in-config-id branch September 7, 2019 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants