Skip to content

Refactor global configuration#446

Merged
nikita-tkachenko-datadog merged 2 commits into
masterfrom
nikita-tkachenko/configuration-refactoring-updated
Dec 11, 2024
Merged

Refactor global configuration#446
nikita-tkachenko-datadog merged 2 commits into
masterfrom
nikita-tkachenko/configuration-refactoring-updated

Conversation

@nikita-tkachenko-datadog

@nikita-tkachenko-datadog nikita-tkachenko-datadog commented Sep 12, 2024

Copy link
Copy Markdown
Collaborator

Requirements for Contributing to this repository

  • Fill out the template below. Any pull request that does not include enough information to be reviewed in a timely manner may be closed at the maintainers' discretion.
  • The pull request must only fix one issue at the time.
  • The pull request must update the test suite to demonstrate the changed functionality.
  • After you create the pull request, all status checks must be pass before a maintainer reviews your contribution. For more details, please see CONTRIBUTING.

What does this PR do?

Refactors global plugin configuration. The following is changed:

  • when configuring agentless mode, it is now possible to just pick a Datadog site instead of manually entering the URLs for different endpoints
  • when specifying DD API key in agentless mode, it is now possible to enter the key manually OR choose the key from Jenkins credentials (earlier it was possible to do both, and it wasn't clear which one takes precedence)
  • DatadogGlobalConfiguration was refactored: it used to contain a flat list of all config properties for different modes (agentless and agentful), now it contains an instance of DatadogClientConfiguration which encapsulates config for the chosen mode (there are different implementations for agentless and agentful modes). The logic for instantiating the correct DatadogClient is also hidden in DatadogClientConfiguration

Description of the Change

Alternate Designs

Possible Drawbacks

Verification Process

Additional Notes

Release Notes

Review checklist (to be filled by reviewers)

  • Feature or bug fix MUST have appropriate tests (unit, integration, etc...)
  • PR title must be written as a CHANGELOG entry (see why)
  • Files changes must correspond to the primary purpose of the PR as described in the title (small unrelated changes should have their own PR)
  • PR must have one changelog/ label attached. If applicable it should have the backward-incompatible label attached.
  • PR should not have do-not-merge/ label attached.
  • If Applicable, issue must have kind/ and severity/ labels attached at least.

@github-actions github-actions Bot added the documentation Documentation related changes label Sep 12, 2024
@nikita-tkachenko-datadog nikita-tkachenko-datadog added the changelog/Fixed Fixed features results into a bug fix version bump label Sep 16, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog force-pushed the nikita-tkachenko/configuration-refactoring-updated branch from 9efa308 to 94211bd Compare September 18, 2024 15:20
@nikita-tkachenko-datadog
nikita-tkachenko-datadog force-pushed the nikita-tkachenko/configuration-refactoring-updated branch from 5f3a210 to d20b98e Compare October 11, 2024 11:01
@nikita-tkachenko-datadog
nikita-tkachenko-datadog marked this pull request as ready for review November 4, 2024 14:15
@nikita-tkachenko-datadog
nikita-tkachenko-datadog force-pushed the nikita-tkachenko/configuration-refactoring-updated branch from d20b98e to b8e26e6 Compare November 20, 2024 10:03
@nikita-tkachenko-datadog
nikita-tkachenko-datadog force-pushed the nikita-tkachenko/configuration-refactoring-updated branch from b8e26e6 to 0404aa5 Compare December 5, 2024 13:41
@nikita-tkachenko-datadog
nikita-tkachenko-datadog force-pushed the nikita-tkachenko/configuration-refactoring-updated branch from 0404aa5 to 0260867 Compare December 5, 2024 15:55

@drodriguezhdez drodriguezhdez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

First pass done. Nice refactor! 🚀

I've dropped some comments (especially important the one related to ensure backwards compatibility when downgrading Jenkins plugin version)

Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/DatadogGlobalConfiguration.java Outdated
Comment on lines +56 to +63
return CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(
StringCredentials.class,
Jenkins.get(),
ACL.SYSTEM,
URIRequirementBuilder.fromUri(null).build()),
CredentialsMatchers.allOf(CredentialsMatchers.withId(credentialId))
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we know if any of these methods can throw a runtime exception? (I was inspecting the code and it does not seem to be the case but 🤷🏻)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't find any. Anyway, I don't think that suppressing the error is better than propagating it in this case. If credentials cannot be retrieved, the error will eventually be propagated to DatadogGlobalConfiguration#configure where it will be logged and updating the config will be aborted.

public abstract int getOrder();
}

public static DatadogIntake getDefaultIntake() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why everything has the prefix default. Is it because this one is the fallback but you can have another non-default instances? Am I missing something?

If only default instances are available, should we remove the prefix default?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These are the values that are used when corresponding property is not configured in the UI.
These methods are mostly to be called from the jelly files, e.g.

varName="apiKey" instance="${instance.apiKey != null ? instance.apiKey : descriptor.defaultApiKey}"

public class MetricsTest {

@Test
public void testIncrementCountAndFlush() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this test is unrelated to the config refactor? Am I missing something?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This test used to live in DatadogClientTest.java. Most of the test cases there became obsolete after the refactoring, this was the only one that was left. I noticed that it had nothing to do with the client and moved it to a place that seemed more appropriate.

Comment on lines +162 to +163
protected XmlFile getConfigFile() {
return new XmlFile(XSTREAM, new File(Jenkins.get().getRootDir(), getId() + ".xml"));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should have a mechanism to avoid breaking the Jenkins config for previous versions:

  • User updates to the new Jenkins plugin version with the config refactor.
  • User modifies config and saves the new config. The file format changes.
  • User tries to downgrade Jenkins plugin to previous version. Cannot start as the file format is unexpected.

A possible approach could be:

  • Store config with a new name (globalConfig_v2.xml) or something like that
  • Try to load v2 config first. If it's not found, try to load legacy config.

With that approach, old Jenkins plugin version should still working.

However, not sure about the Config-as-Code format 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's a great idea! I implemented the _v2 storing/loading.
As for CasC, the config reads from it but does not write, meaning YAMLs will remain the same unless users change them manually (the new code is compatible with the old YAMLs). So it's not that big a problem as the one with XMLs.

@drodriguezhdez drodriguezhdez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Great job

@nikita-tkachenko-datadog
nikita-tkachenko-datadog merged commit 4272c9b into master Dec 11, 2024
@nikita-tkachenko-datadog
nikita-tkachenko-datadog deleted the nikita-tkachenko/configuration-refactoring-updated branch December 11, 2024 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/Fixed Fixed features results into a bug fix version bump documentation Documentation related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants