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

Add Remote Config Rollback operation #885

Merged
merged 5 commits into from
May 15, 2020

Conversation

lahirumaramba
Copy link
Member

@lahirumaramba lahirumaramba commented May 11, 2020

  • Add rollback operation to the RC API
  • Add unit tests

Note: The API proposal is still under review. Getting a head start here.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple of nits.

src/index.d.ts Outdated
@@ -1025,6 +1025,18 @@ declare namespace admin.remoteConfig {
*/
publishTemplate(template: RemoteConfigTemplate, options?: { force: boolean }): Promise<RemoteConfigTemplate>;

/**
* Rollbacks a project's published Remote Config template to the one specified by the provided
Copy link
Contributor

Choose a reason for hiding this comment

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

"... to the specified version."

return this.httpClient.send(request);
})
.then((resp) => {
if (!validator.isNonEmptyString(resp.headers['etag'])) {
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 assume this logic is used by at least one other method (getTemplate). Extract into a helper method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Moved to a helper method. Thanks!

@lahirumaramba
Copy link
Member Author

Hi @egilmorez ! Please review the docstrings in index.d.ts. Thank you!

Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

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

Some things to look at Lahiru, thanks!

src/index.d.ts Outdated
@@ -1025,6 +1025,18 @@ declare namespace admin.remoteConfig {
*/
publishTemplate(template: RemoteConfigTemplate, options?: { force: boolean }): Promise<RemoteConfigTemplate>;

/**
* Rollbacks a project's published Remote Config template to the specified version.
Copy link
Contributor

Choose a reason for hiding this comment

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

Despite the noun "rollback" we still would way "Rolls back a project's . . . "

src/index.d.ts Outdated
/**
* Rollbacks a project's published Remote Config template to the specified version.
* A rollback is equivalent to getting a previously published Remote Config
* template, and re-publishing it using a force update.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest omitting the comma here.

src/index.d.ts Outdated
* template, and re-publishing it using a force update.
*
* @param versionNumber The version number of the Remote Config template to rollback to.
* The specified version number must be less than the current version number, and not have
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest "lower than"

@lahirumaramba
Copy link
Member Author

Thanks @egilmorez ! Updated.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

One tiny change related to the shared util.

'ETag header is not present in the server response.');
}
this.validateResponseEtag(resp.headers['etag']);
return {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can also go into a util right? Something like:

return this.createRemoteConfigTemplate(resp);

The util can do the validation and then extract the right properties from the response.

Copy link
Member Author

Choose a reason for hiding this comment

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

Great point! Moved the creation to a new util. Thanks!

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of nits to think about.

conditions: resp.data.conditions,
parameters: resp.data.parameters,
parameterGroups: resp.data.parameterGroups,
etag: etag,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: You can just do etag, here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@@ -140,16 +134,11 @@ export class RemoteConfigApiClient {
this.validateRemoteConfigTemplate(template);
return this.sendPutRequest(template, template.etag, true)
.then((resp) => {
// validating a template returns an etag with the suffix -0 means that your update
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we ever check for this -0 suffix?

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't necessarily check for -0 suffix here. If the response is not an error (200 OK) and contains a valid etag, we can safely assume that the template was successfully validated. All other cases should return an error code. I will add an additional check for the -0 suffix in a separate PR for good measure :)

*/
private toRemoteConfigTemplate(resp: HttpResponse, customEtag?: string): RemoteConfigTemplate {
const etag = (typeof customEtag == 'undefined') ? resp.headers['etag'] : customEtag;
this.validateResponseEtag(etag);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This should be called something like validateEtag() now.

@lahirumaramba lahirumaramba merged commit 5762470 into remote-config-vc May 15, 2020
@lahirumaramba lahirumaramba deleted the lm-rc-v2-rollback branch May 15, 2020 17:51
lahirumaramba added a commit that referenced this pull request Jun 25, 2020
* Get remote config template by version number (#874)

* Get remote config template by version number

* Refactor unit tests for Remote Config (#884)

* Refactor unit tests

* Add Remote Config Rollback operation (#885)

* Add Remote Config Rollback operation

* Update docs and move etag validation to a helper function

* Update docs

* Introduce a util to create a template from API response

* PR fixes

* Remote Config Add list versions operation (#896)

* Remote Config: Add list versions operation

* Add version Impl and other PR fixes

* PR fixes

* Imrpoved unit tests and some code clean up

* Fix code formatting

* Add a separate function to get a Template with version (#902)

* Add version meta data to RC templates (#906)

* Add version meta data to RC templates

* PR fixes

* Use assertion to unwrap template.version

* Update Remote Config Docstrings in index.d.ts
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

3 participants