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

Allow configuring max aliases for a collection #1375

Merged
merged 8 commits into from May 24, 2020
Merged

Allow configuring max aliases for a collection #1375

merged 8 commits into from May 24, 2020

Conversation

jetersen
Copy link
Member

@jetersen jetersen commented May 8, 2020

fixes #1374

Your checklist for this pull request

🚨 Please review the guidelines for contributing to this repository.

  • Make sure you are requesting to pull a topic/feature/bugfix branch (right side) and not your master branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or in Jenkins JIRA
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Did you provide a test-case? That demonstrates feature works or fixes the issue.

@codecov
Copy link

codecov bot commented May 8, 2020

Codecov Report

Merging #1375 into master will decrease coverage by 0.09%.
The diff coverage is 78.26%.

@@             Coverage Diff              @@
##             master    #1375      +/-   ##
============================================
- Coverage     79.61%   79.52%   -0.10%     
- Complexity      804      806       +2     
============================================
  Files            66       66              
  Lines          2330     2344      +14     
  Branches        325      326       +1     
============================================
+ Hits           1855     1864       +9     
- Misses          375      380       +5     
  Partials        100      100              
Impacted Files Coverage Δ Complexity Δ
...n/java/io/jenkins/plugins/casc/yaml/YamlUtils.java 75.80% <54.54%> (-6.02%) 15.00 <1.00> (ø)
...a/io/jenkins/plugins/casc/ConfigurationAsCode.java 75.54% <100.00%> (+0.06%) 101.00 <0.00> (ø)
.../io/jenkins/plugins/casc/ConfigurationContext.java 85.18% <100.00%> (+1.85%) 18.00 <2.00> (+2.00)

@jetersen jetersen added the bugfix A PR that fixes a bug - used by Release Drafter label May 8, 2020
…ases config

This needs to be a property/env since the context is not yet configurable as it has yet to read any YAML
and it might be blocked due to alias limit.

Adding the reading of the property/env to ConfigurationContext
makes sense to avoid YamlUtils to constantly reading the property on every file read
when it attempts to merge all the sources.
Comment on lines +42 to +46
String prop = Util.fixEmptyAndTrim(System.getProperty(
CASC_YAML_MAX_ALIASES_PROPERTY,
System.getenv(CASC_YAML_MAX_ALIASES_ENV)
));
yamlMaxAliasesForCollections = NumberUtils.toInt(prop, 50);
Copy link
Member Author

Choose a reason for hiding this comment

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

@timja Please see 57aebdd commit message for my reasoning to use a property.

This needs to be a property/env since the context is not yet configurable as it has yet to read any YAML
and it might be blocked due to alias limit.

Adding the reading of the property/env to ConfigurationContext
makes sense to avoid YamlUtils to constantly reading the property on every file read
when it attempts to merge all the sources.

@jetersen
Copy link
Member Author

I would like to add tests for aliases and demo.
To potentially close #1246

@jetersen jetersen changed the title increase max aliases for collection allow configurable max aliases for collection May 24, 2020
@jetersen
Copy link
Member Author

No need for documentation it as the exception will tell them what to do.

@jetersen jetersen marked this pull request as ready for review May 24, 2020 15:12
@jetersen jetersen requested a review from a team as a code owner May 24, 2020 15:12
@@ -27,14 +26,14 @@
@Test
public void testAMaxOfOneEnv() {
env.set(ConfigurationContext.CASC_YAML_MAX_ALIASES_ENV, "1");
assertThrows(YAMLException.class, () ->
assertThrows(ConfiguratorException.class, () ->
Copy link
Member

Choose a reason for hiding this comment

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

Worth checking the message 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.

assertThrows does not allow for asserting the exception message.

Copy link
Member

Choose a reason for hiding this comment

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

It returns the exception and then you can assert on it

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh it returns the exception so sure 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

The stack trace somewhat hides it but it is still visible.

io.jenkins.plugins.casc.ConfiguratorException: Failed to read YamlSource: file:/C:/git/code/configuration.as.code.plugin/test-harness/target/test-classes/io/jenkins/plugins/casc/maxAliasesLimit.yml
	at io.jenkins.plugins.casc.yaml.YamlUtils.merge(YamlUtils.java:48)
	at io.jenkins.plugins.casc.yaml.YamlUtils.loadFrom(YamlUtils.java:127)
	at io.jenkins.plugins.casc.ConfigurationAsCode.configureWith(ConfigurationAsCode.java:618)
	at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:587)
	at io.jenkins.plugins.casc.ConfigurationAsCode.configure(ConfigurationAsCode.java:576)
	at io.jenkins.plugins.casc.YamlMaxAliasesCollection.lambda$testAMaxOfOneProp$1(YamlMaxAliasesCollection.java:42)
	at org.junit.Assert.assertThrows(Assert.java:1001)
	at org.junit.Assert.assertThrows(Assert.java:981)
	at io.jenkins.plugins.casc.YamlMaxAliasesCollection.testAMaxOfOneProp(YamlMaxAliasesCollection.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:597)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:288)
	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:282)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.lang.Thread.run(Thread.java:748)
Caused by: io.jenkins.plugins.casc.ConfiguratorException: Number of aliases for non-scalar nodes exceeds the specified max=1
You can increase the maximum by setting an environment variable or property
  ENV: CASC_YAML_MAX_ALIASES="100"
  PROPERTY: -Dcasc.yaml.max.aliases="100"
	at io.jenkins.plugins.casc.yaml.YamlUtils.read(YamlUtils.java:66)
	at io.jenkins.plugins.casc.yaml.YamlUtils.merge(YamlUtils.java:38)
	... 21 more

@timja timja changed the title allow configurable max aliases for collection Allow configuring max aliases for collection May 24, 2020
@timja timja changed the title Allow configuring max aliases for collection Allow configuring max aliases for a collection May 24, 2020
@jetersen
Copy link
Member Author

jacoco does not like assertThrows for code coverage 😓

@jetersen jetersen merged commit 28622da into jenkinsci:master May 24, 2020
@jetersen jetersen deleted the fix/1374 branch May 24, 2020 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix A PR that fixes a bug - used by Release Drafter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

org.yaml.snakeyaml.error.YAMLException: Number of aliases for non-scalar nodes exceeds the specified max=50
2 participants