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

Owlbot should keep track of custom modifications to templates #1798

Closed
kolea2 opened this issue May 2, 2023 · 24 comments · Fixed by #1876
Closed

Owlbot should keep track of custom modifications to templates #1798

kolea2 opened this issue May 2, 2023 · 24 comments · Fixed by #1876
Assignees
Labels
lang: java Issues specific to Java. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@kolea2
Copy link
Collaborator

kolea2 commented May 2, 2023

We have some examples of libraries that make modifications to otherwise standard templates. For example, https://github.com/googleapis/java-bigtable/blob/main/.kokoro/presubmit/integration.cfg#L9-L12 adds custom IT args to this standard template: https://github.com/googleapis/synthtool/blob/master/synthtool/gcp/templates/java_library/.kokoro/presubmit/integration.cfg. As such, we need to exclude it from owlbot and any new iterations of these templates need to be handled manually (see googleapis/java-bigtable#1255 and fix googleapis/java-bigtable#1258).

It would be great if owlbot could preserve known additions to templates so we can still receive updates without having to do manual work on them in a repeated way.

@kolea2 kolea2 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p3 Desirable enhancement or fix. May not be included in next release. labels May 2, 2023
@SurferJeffAtGoogle
Copy link
Contributor

If you add integration.cfg to the list of excludes here
https://github.com/googleapis/java-bigtable/blob/722c6c58e42c51ac414a7e189c711e844447b9ce/owlbot.py#L98
then Owl Bot won't touch it. Will that satisfy your needs?

@kolea2
Copy link
Collaborator Author

kolea2 commented May 9, 2023

integration.cfg is already excluded. I would like to not exclude any templates, but have owlbot insert custom arguments specific to the library (in this case, INTEGRATION_TEST_ARGS).

@SurferJeffAtGoogle
Copy link
Contributor

I see. That logic can be coded into owlbot.py and synthtool. In other words, it's a feature request for your post processor (https://github.com/googleapis/synthtool).

@kolea2 kolea2 transferred this issue from googleapis/repo-automation-bots May 11, 2023
@kolea2
Copy link
Collaborator Author

kolea2 commented May 11, 2023

Transferring to appropriate repo and reopening.

@kolea2 kolea2 reopened this May 11, 2023
@SurferJeffAtGoogle SurferJeffAtGoogle added the lang: java Issues specific to Java. label May 22, 2023
@suztomo
Copy link
Member

suztomo commented May 24, 2023

The problem is that the granularity of owlbot.py exclusion logic (implemented by java.common_templates(excludes=[ ... (usage link) is file-level and this is too coarse grained to meet this issue.

Rough idea 1: Somehow we use Git's merging capability.

Rough idea 2: INTEGRATION_TEST_ARGS to be in independent file that the build.sh reads if one exists.

I'll think more.

@kolea2
Copy link
Collaborator Author

kolea2 commented May 25, 2023

@suztomo just building off of your second idea a bit - something similar to https://github.com/googleapis/java-bigtable/blob/main/.readme-partials.yml which inserts custom things into our READMEs could work here as well. Would also work nicely if new environment variables need to be introduced in the future.

@suztomo
Copy link
Member

suztomo commented May 26, 2023

Found that https://github.com/googleapis/synthtool/blob/master/synthtool/gcp/partials.py Thank you for information.

Is INTEGRATION_TEST_ARGS the only thing we should worry about?

This is the list of files excluded from templating.

java.common_templates(excludes=[
    '.gitignore',
    '.kokoro/presubmit/integration.cfg',
    '.kokoro/presubmit/graalvm-native.cfg',
    '.kokoro/presubmit/graalvm-native-17.cfg',
    '.kokoro/nightly/integration.cfg',
    '.kokoro/presubmit/samples.cfg',
    '.kokoro/nightly/samples.cfg',
suztomo@suztomo2:~/synthtool$ for N in presubmit/integration.cfg presubmit/graalvm-native.cfg presubmit/graalvm-native-17.cfg nightly/integration.cfg presubmit/samples.cfg nightly/samples.cfg; do diff --unified=0 ~/java-bigtable/.kokoro/${N} ~/synthtool/synthtool/gcp/templates/java_library/.kokoro/${N}; done
--- /usr/local/google/home/suztomo/java-bigtable/.kokoro/presubmit/integration.cfg	2022-06-27 10:45:58.426916784 -0400
+++ /usr/local/google/home/suztomo/synthtool/synthtool/gcp/templates/java_library/.kokoro/presubmit/integration.cfg	2022-05-17 12:20:33.234220468 -0400
@@ -10,5 +9,0 @@
-    key: "INTEGRATION_TEST_ARGS"
-    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
-}
-
-env_vars: {
--- /usr/local/google/home/suztomo/java-bigtable/.kokoro/presubmit/graalvm-native.cfg	2023-05-19 10:53:32.462094047 -0400
+++ /usr/local/google/home/suztomo/synthtool/synthtool/gcp/templates/java_library/.kokoro/presubmit/graalvm-native.cfg	2023-05-18 13:24:15.185686922 -0400
@@ -21,5 +20,0 @@
-    key: "INTEGRATION_TEST_ARGS"
-    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
-}
-
-env_vars: {
--- /usr/local/google/home/suztomo/java-bigtable/.kokoro/presubmit/graalvm-native-17.cfg	2023-05-19 10:53:32.462094047 -0400
+++ /usr/local/google/home/suztomo/synthtool/synthtool/gcp/templates/java_library/.kokoro/presubmit/graalvm-native-17.cfg	2023-05-18 13:24:15.185686922 -0400
@@ -14,5 +13,0 @@
-env_vars: {
-    key: "INTEGRATION_TEST_ARGS"
-    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
-}
-
@@ -38 +33 @@
-}
+}
\ No newline at end of file
--- /usr/local/google/home/suztomo/java-bigtable/.kokoro/nightly/integration.cfg	2022-06-27 10:45:58.426916784 -0400
+++ /usr/local/google/home/suztomo/synthtool/synthtool/gcp/templates/java_library/.kokoro/nightly/integration.cfg	2022-11-01 13:39:05.609656779 -0400
@@ -10,5 +9,0 @@
-    key: "INTEGRATION_TEST_ARGS"
-    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
-}
-
-env_vars: {
@@ -21 +16 @@
-  value: "gcloud-devel"
+  value: "java-docs-samples-testing"
@@ -26 +21 @@
-  value: "gcloud-devel"
+  value: "java-docs-samples-testing"
@@ -30,2 +25,2 @@
-  key: "ENABLE_BUILD_COP"
-  value: "true"
+  key: "ENABLE_FLAKYBOT"
+  value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %}
--- /usr/local/google/home/suztomo/java-bigtable/.kokoro/presubmit/samples.cfg	2022-06-27 10:45:58.430916747 -0400
+++ /usr/local/google/home/suztomo/synthtool/synthtool/gcp/templates/java_library/.kokoro/presubmit/samples.cfg	2022-05-17 12:20:33.238220432 -0400
@@ -33,5 +32,0 @@
-}
-
-env_vars: {
-  key: "BIGTABLE_TESTING_INSTANCE"
-  value: "instance"
--- /usr/local/google/home/suztomo/java-bigtable/.kokoro/nightly/samples.cfg	2022-06-27 10:45:58.426916784 -0400
+++ /usr/local/google/home/suztomo/synthtool/synthtool/gcp/templates/java_library/.kokoro/nightly/samples.cfg	2022-11-01 13:39:05.613656740 -0400
@@ -36,2 +36,2 @@
-  key: "ENABLE_BUILD_COP"
-  value: "true"
+  key: "ENABLE_FLAKYBOT"
+  value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %}
@@ -39,5 +38,0 @@
-
-env_vars: {
-  key: "BIGTABLE_TESTING_INSTANCE"
-  value: "instance"
-}
\ No newline at end of file

@suztomo
Copy link
Member

suztomo commented Jun 6, 2023

In addition to INTEGRATION_TEST_ARGS, there are other environment variables that differ from the template: gcloud-devel BIGTABLE_TESTING_INSTANCE.

Now I'm feeing a solution similar to .readme-partials.yml is better to accommodate different needs

@kolea2
Copy link
Collaborator Author

kolea2 commented Jun 6, 2023

@suztomo once googleapis/java-datastore#1102 is merged, we will also have DATASTORE_PROJECT_ID. All to say, yes - there are env variables other than INTEGRATION_TEST_ARGS (and new ones can always be added in the future).

@suztomo
Copy link
Member

suztomo commented Jun 6, 2023

@kolea2 Got it.

Idea of partial files for env_vars

.kokoro/nightly/.samples.cfg.partials.yml. (In general, its .<cfg file name>.partials.yml in the same directory). The YAML file contains the following section:

env_vars:
- key: INTEGRATION_TEST_ARGS
  value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
- key: DATASTORE_PROJECT_ID
  value: java-docs-samples-testing

When OwlBot post processor generates the templated file with ".cfg", it looks for .<cfg file name>.partials.yml in the GitHub repository. If the partial YAML file exists, then it does the following to the generated file:

  • If the template already has the key for env_vars , then it overrides the value.
  • If the template does not have the key for the env_vars, then it adds a new env_vars.

What about other fields than env_vars?

For now I focus on env_vars only. This design allows us to extend other fields than env_vars.

@suztomo suztomo removed their assignment Sep 20, 2023
@JoeWang1127 JoeWang1127 self-assigned this Sep 22, 2023
@JoeWang1127
Copy link
Contributor

@suztomo I found that load_partials is called in common_templates to load key-value pairs from partial files.

I can add an additional parameter to common_templates, called partial_files with default value, to load partials other than .readme-partials.yml or .readme-partials.yaml into the templates.

Then in owlbot.py, to load partials:

java.common_templates(
  excludes=[
    '.gitignore',
    '.kokoro/presubmit/integration.cfg',
    '.kokoro/presubmit/graalvm-native.cfg',
    '.kokoro/presubmit/graalvm-native-17.cfg',
  ],
  partial_files=[".kokoro/nightly/integration.cfg-partials.yaml"]
)

WDYT?

@suztomo
Copy link
Member

suztomo commented Sep 25, 2023

@JoeWang1127 Good start. Before implementing it, would you write down what ".kokoro/nightly/integration.cfg-partials.yaml" would look like?

@JoeWang1127
Copy link
Contributor

This is a sample of .kokoro/nightly/integration.cfg-partials.yaml.
Everything from the 2nd line will be inserted into .kokoro/nightly/integration.cfg.

kokoro_nightly_integration: |
  env_vars: {
    key: "INTEGRATION_TEST_ARGS"
    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
  }

In the template, we need to add the following section:

{% if 'partials' in metadata and metadata['partials']['kokoro_nightly_integration'] %}
{{ metadata['partials']['kokoro_nightly_integration'] }}
{% endif %}

@suztomo
Copy link
Member

suztomo commented Sep 25, 2023

@JoeWang1127 What about the difference between gcloud-devel proejct and java-docs-samples-testing project?

-  value: "gcloud-devel"
+  value: "java-docs-samples-testing"

@JoeWang1127
Copy link
Contributor

The contents of partials can only be inserted into templates, so two env_vars can't be merged even if they have the same key.

@suztomo
Copy link
Member

suztomo commented Sep 25, 2023

Good. Then the current load_partials does not work well for the cfg files. Would you design something better? Start with an ideal integration.cfg-partials.yaml file.

@JoeWang1127
Copy link
Contributor

I think integration.cfg-partials.yaml can be:

kokoro_nightly_integration:
  - key: "INTEGRATION_TEST_ARGS"
    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
  - key: "GCLOUD_PROJECT"
    value: "gcloud-devel"

If the key is not presented in the template, then the key-value pair is inserted to the template; otherwise the value will be overwritten. Something like you mentioned.

The template needs redesign and a new file integration.cfg-default.yaml to hold default key-value pairs.

@suztomo
Copy link
Member

suztomo commented Sep 25, 2023

It reads as if it only takes care of envvars implicitly.

@JoeWang1127
Copy link
Contributor

In the template, it says the format of integration.cfg is defined in //devtools/kokoro/config/proto/build.proto, but I can't find this file in google3.

If we need other keys besides env_vars, then integration.cfg-partials.yaml can be:

kokoro_nightly_integration:
    env_vars:
        - key: "INTEGRATION_TEST_ARGS"
          value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
        - key: "GCLOUD_PROJECT"
          value: "gcloud-devel"

@suztomo
Copy link
Member

suztomo commented Sep 25, 2023

I feel the 1st line "kokoro_nightly_integration:" is redundant, assuming integration.cfg-partials.yaml file is in .kokoro/nightly/ directory.

@JoeWang1127
Copy link
Contributor

JoeWang1127 commented Sep 25, 2023

I use kokoro_nightly_integration to specify all key-value pairs should go into .kokoro/nightly/integration.cfg.

I think I can parse the file name so that all key-value pairs in .kokoro/nightly/integration.cfg-partials.yaml can go into .kokoro/nightly/integration.cfg.

Then integration.cfg-partials.yaml is:

env_vars:
  - key: "INTEGRATION_TEST_ARGS"
    value: "-P bigtable-emulator-it,bigtable-prod-it,bigtable-prod-batch-it -Dbigtable.project=gcloud-devel -Dbigtable.instance=google-cloud-bigtable -Dbigtable.table=integration-tests -Dbigtable.kms_key_name=projects/gcloud-devel/locations/us-east1/keyRings/cmek-test-key-ring/cryptoKeys/cmek-test-key -Dbigtable.wait-for-cmek-key-status=true"
  - key: "GCLOUD_PROJECT"
    value: "gcloud-devel"

@kolea2
Copy link
Collaborator Author

kolea2 commented Sep 26, 2023

@JoeWang1127 thanks for digging into this!

One question - I noticed you're specifying the nightly directory, but we'd want this to take effect on all integration configurations (nighty, presubmit, nightly/java11-integration). Does this account for that?

@JoeWang1127
Copy link
Contributor

Hi @kolea2, you can specify customized env_vars for different configuration files, but you need to provide a partial file for each of the template and the partial file and template should be in the same directory.

For example, if you want to define env_vars for .kokoro/nightly/integration.cfg and .kokoro/presubmit/integration.cfg, you need to provide .kokoro/nightly/integration.cfg-partial.yaml and .kokoro/presubmit/integration.cfg-partial.yaml

I mainly focus on env_vars right now, but this design can be extended to add other keys, though we need to modify the template.

Does this sound good to you?

@JoeWang1127
Copy link
Contributor

Since I haven't heard more feedback, I'll start to implement as #1798 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: java Issues specific to Java. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants