Skip to content

feat(parametermanager): Added samples for get, list and render regional parameter & parameter version #10061

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

Conversation

durgesh-ninave-crest
Copy link
Contributor

Description

Added samples for viewing, listing and rendering parameter and parameter versions using Parameter Manager SDK

Sample List (regional):

  1. list-all-parameters
  2. view-parameter-details
  3. list-all-parameters-versions
  4. view-parameter-version-details
  5. render-secret-parameter-version

Also added required Tests for the same.

Checklist

  • I have followed Sample Format Guide
  • pom.xml parent set to latest shared-configuration
  • Appropriate changes to README are included in PR
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • Tests pass: mvn clean verify required
  • Lint passes: mvn -P lint checkstyle:check required
  • Static Analysis: mvn -P lint clean compile pmd:cpd-check spotbugs:check advisory only
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Copy link

snippet-bot bot commented Apr 8, 2025

Here is the summary of changes.

You are about to add 5 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Apr 8, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @durgesh-ninave-crest, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request adds samples for viewing, listing, and rendering parameter and parameter versions using the Parameter Manager SDK. It includes samples for listing all parameters, viewing parameter details, listing all parameter versions, viewing parameter version details, and rendering a secret parameter version. The pull request also includes the required tests for the new samples.

Highlights

  • New samples: Added samples for listing, viewing, and rendering regional parameters and their versions using the Parameter Manager SDK.
  • Regional Parameter Manager: The samples use the regional endpoint for the Parameter Manager API, ensuring that the operations are performed in the specified region.
  • Testing: Added new tests to verify the functionality of the new samples.

Changelog

Click here to see the changelog
  • parametermanager/src/main/java/parametermanager/regionalsamples/GetRegionalParam.java
    • Added a new class to demonstrate how to get a regional parameter using the Parameter Manager SDK.
    • Includes a method to get a regional parameter by project ID, location ID, and parameter ID.
    • Uses the ParameterManagerClient to interact with the Parameter Manager API.
  • parametermanager/src/main/java/parametermanager/regionalsamples/GetRegionalParamVersion.java
    • Added a new class to demonstrate how to get a regional parameter version using the Parameter Manager SDK.
    • Includes a method to get a regional parameter version by project ID, location ID, parameter ID, and version ID.
    • Uses the ParameterManagerClient to interact with the Parameter Manager API.
  • parametermanager/src/main/java/parametermanager/regionalsamples/ListRegionalParamVersions.java
    • Added a new class to list parameter versions for a specified region using the Parameter Manager SDK.
    • Includes a method to list all parameter versions regionally by project ID, location ID, and parameter ID.
    • Uses the ParameterManagerClient to interact with the Parameter Manager API.
  • parametermanager/src/main/java/parametermanager/regionalsamples/ListRegionalParams.java
    • Added a new class to demonstrate listing parameters for a specified region using the Parameter Manager SDK.
    • Includes a method to list all parameters in a given region by project ID and location ID.
    • Uses the ParameterManagerClient to interact with the Parameter Manager API.
  • parametermanager/src/main/java/parametermanager/regionalsamples/RenderRegionalParamVersion.java
    • Added a new class to demonstrate how to render a regional parameter version using the Parameter Manager SDK.
    • Includes a method to render a regional parameter version by project ID, location ID, parameter ID, and version ID.
    • Uses the ParameterManagerClient to interact with the Parameter Manager API.
  • parametermanager/src/test/java/parametermanager/regionalsamples/SnippetsIT.java
    • Added tests for the new samples, including tests for getting, listing, and rendering regional parameters and their versions.
    • Includes setup and teardown methods to create and delete test resources.
    • Added methods to create and manage secrets for testing the render parameter version functionality (lines 291-370).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


In regions code takes flight,
Parameters managed, day and night,
Versions render,
Secrets surrender,
SDK samples, shining bright.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request adds samples for viewing, listing, and rendering regional parameters and parameter versions using the Parameter Manager SDK. The changes include new classes for each sample and corresponding tests. Overall, the code is well-structured and follows the sample format guide. However, there are a few areas that could be improved for clarity and efficiency.

Summary of Findings

  • TODO comments: The code contains TODO comments that should be replaced with actual values before merging. These comments indicate areas where developers need to provide specific project and parameter information.
  • Redundant endpoint configuration: The endpoint configuration is repeated in multiple files. Consider creating a utility method or constant to avoid duplication and improve maintainability.
  • Thread.sleep usage: The use of Thread.sleep in the test setup is not ideal for integration tests. Explore alternative approaches for ensuring resources are available before proceeding with tests.

Merge Readiness

The pull request is not quite ready for merging. The TODO comments need to be addressed, and the redundant endpoint configuration should be refactored. The Thread.sleep usage in the tests should also be reviewed and potentially replaced with a more robust solution. I am unable to approve this pull request, and recommend that others review and approve this code before merging.

Comment on lines +33 to +36
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";

Choose a reason for hiding this comment

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

high

These TODO comments should be replaced with actual values before merging. Consider adding a comment explaining the purpose of each variable.

Suggested change
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id"; // Project to create parameter in.
String locationId = "your-location-id"; // Location of the parameter.
String parameterId = "your-parameter-id"; // ID of the parameter.

Comment on lines +34 to +38
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";
String versionId = "your-version-id";

Choose a reason for hiding this comment

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

high

These TODO comments should be replaced with actual values before merging. Consider adding a comment explaining the purpose of each variable.

Suggested change
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";
String versionId = "your-version-id";
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id"; // Project to create parameter in.
String locationId = "your-location-id"; // Location of the parameter.
String parameterId = "your-parameter-id"; // ID of the parameter.
String versionId = "your-version-id"; // Version of the parameter.

Comment on lines +35 to +38
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";

Choose a reason for hiding this comment

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

high

These TODO comments should be replaced with actual values before merging. Consider adding a comment explaining the purpose of each variable.

Suggested change
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id"; // Project to create parameter in.
String locationId = "your-location-id"; // Location of the parameter.
String parameterId = "your-parameter-id"; // ID of the parameter.

Comment on lines +34 to +36
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";

Choose a reason for hiding this comment

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

high

These TODO comments should be replaced with actual values before merging. Consider adding a comment explaining the purpose of each variable.

Suggested change
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id"; // Project to create parameter in.
String locationId = "your-location-id"; // Location of the parameter.

Comment on lines +34 to +38
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";
String versionId = "your-version-id";

Choose a reason for hiding this comment

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

high

These TODO comments should be replaced with actual values before merging. Consider adding a comment explaining the purpose of each variable.

Suggested change
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id";
String locationId = "your-location-id";
String parameterId = "your-parameter-id";
String versionId = "your-version-id";
// TODO(developer): Replace these variables before running the sample.
String projectId = "your-project-id"; // Project to create parameter in.
String locationId = "your-location-id"; // Location of the parameter.
String parameterId = "your-parameter-id"; // ID of the parameter.
String versionId = "your-version-id"; // Version of the parameter.

Comment on lines +45 to +48
// Endpoint to call the regional parameter manager server
String apiEndpoint = String.format("parametermanager.%s.rep.googleapis.com:443", locationId);
ParameterManagerSettings parameterManagerSettings =
ParameterManagerSettings.newBuilder().setEndpoint(apiEndpoint).build();

Choose a reason for hiding this comment

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

medium

The endpoint configuration is repeated in multiple files. Consider creating a utility method or constant to avoid duplication and improve maintainability.

// Endpoint to call the regional parameter manager server
    String apiEndpoint = String.format("parametermanager.%s.rep.googleapis.com:443", locationId);
    ParameterManagerSettings parameterManagerSettings = ParameterManagerSettings.newBuilder().setEndpoint(apiEndpoint).build();

    //Consider refactoring to:
    //private static final String API_ENDPOINT_FORMAT = "parametermanager.%s.rep.googleapis.com:443";
    //String apiEndpoint = String.format(API_ENDPOINT_FORMAT, locationId);
    //ParameterManagerSettings parameterManagerSettings = ParameterManagerSettings.newBuilder().setEndpoint(apiEndpoint).build();

Comment on lines +164 to +167
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
throw new RuntimeException(e);

Choose a reason for hiding this comment

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

medium

The use of Thread.sleep is generally discouraged in integration tests as it can lead to flaky tests and increased test execution time. Consider using a more robust approach, such as polling or waiting for a specific condition to be met.

      try {
        Thread.sleep(60000);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }

      //Consider refactoring to:
      //long startTime = System.currentTimeMillis();
      //while (!isSecretAvailable(SECRET_NAME) && System.currentTimeMillis() - startTime < 60000) {
      //  Thread.sleep(1000); // Poll every 1 second
      //}
      //if (!isSecretAvailable(SECRET_NAME)) {
      //  throw new RuntimeException("Secret not available after 60 seconds");
      //}

@grayside grayside removed their assignment Apr 8, 2025
@gptSanyam gptSanyam added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 9, 2025
@kokoro-team kokoro-team removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 9, 2025
@arpangoswami arpangoswami merged commit 47fd761 into GoogleCloudPlatform:main Apr 9, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants