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

[fix] Allow setting sourceType in config file #19836

Merged
merged 4 commits into from
Aug 31, 2023

Conversation

alpreu
Copy link
Contributor

@alpreu alpreu commented Mar 16, 2023

Motivation

Currently, there is an inconsistency between sinks and sources. Sinks can be created by passing the whole config in the sinkConfig file:

./bin/pulsar-admin sinks create --sink-config-file <file-name>.yaml

But Sources cannot. If we do the equivalent:

./bin/pulsar-admin sources create --source-config-file <file-name>.yaml
>Source archive not specified

To make it work, we currently have to explicitly pass in the type parameter:

./bin/pulsar-admin sources create --source-config-file <file-name>.yaml --source-type foo

Modifications

Add the sourceType to SourceConfig so it can be passed through the config file too.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • extended TestCmdSources

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

Matching PR in forked repository

PR in forked repository: alpreu#9

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 16, 2023
@@ -449,6 +449,8 @@ void processArguments() throws Exception {

if (sourceType != null) {
sourceConfig.setArchive(validateSourceType(sourceType));
} else if (sourceConfig.getSourceType() != null) {
sourceConfig.setArchive(validateSourceType(sourceType));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sourceConfig.setArchive(validateSourceType(sourceType));
sourceConfig.setArchive(validateSourceType(sourceConfig.getSourceType()));

Copy link
Member

Choose a reason for hiding this comment

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

Updated.

@@ -412,6 +412,15 @@ public void testBatchSourceConfigMissingDiscoveryTriggererClassName() throws Exc
expectedSourceConfig.setBatchSourceConfig(batchSourceConfig);
testCmdSourceConfigFile(testSourceConfig, expectedSourceConfig);
}

@Test(expectedExceptions = ParameterException.class, expectedExceptionsMessageRegExp = "Invalid source type 'foo' " +
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a happy path test ?

Copy link
Member

Choose a reason for hiding this comment

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

I tried it:

    @Test
    public void testCmdSourceConfigFileSourceType() throws Exception {
        ConnectorDefinition mockDefinition = new ConnectorDefinition();
        mockDefinition.setName("builtin");
        when(source.getBuiltInSources()).thenReturn(List.of(mockDefinition));

        SourceConfig sourceConfig = getSourceConfig();
        sourceConfig.setSourceType("builtin");

        SourceConfig exceptedConfig = getSourceConfig();
        exceptedConfig.setSourceType("builtin");
        exceptedConfig.setArchive("builtin://builtin");

        testCmdSourceConfigFile(sourceConfig, exceptedConfig);
    }
    

... while due to some dirty code inherit local run from cmd source the tests are hard to tune. That said, validateSourceType is inherited by LocalSourceRunner with total different manner.

@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Apr 16, 2023
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -449,6 +449,8 @@ void processArguments() throws Exception {

if (sourceType != null) {
sourceConfig.setArchive(validateSourceType(sourceType));
} else if (sourceConfig.getSourceType() != null) {
sourceConfig.setArchive(validateSourceType(sourceType));
Copy link
Member

Choose a reason for hiding this comment

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

Updated.

@@ -412,6 +412,15 @@ public void testBatchSourceConfigMissingDiscoveryTriggererClassName() throws Exc
expectedSourceConfig.setBatchSourceConfig(batchSourceConfig);
testCmdSourceConfigFile(testSourceConfig, expectedSourceConfig);
}

@Test(expectedExceptions = ParameterException.class, expectedExceptionsMessageRegExp = "Invalid source type 'foo' " +
Copy link
Member

Choose a reason for hiding this comment

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

I tried it:

    @Test
    public void testCmdSourceConfigFileSourceType() throws Exception {
        ConnectorDefinition mockDefinition = new ConnectorDefinition();
        mockDefinition.setName("builtin");
        when(source.getBuiltInSources()).thenReturn(List.of(mockDefinition));

        SourceConfig sourceConfig = getSourceConfig();
        sourceConfig.setSourceType("builtin");

        SourceConfig exceptedConfig = getSourceConfig();
        exceptedConfig.setSourceType("builtin");
        exceptedConfig.setArchive("builtin://builtin");

        testCmdSourceConfigFile(sourceConfig, exceptedConfig);
    }
    

... while due to some dirty code inherit local run from cmd source the tests are hard to tune. That said, validateSourceType is inherited by LocalSourceRunner with total different manner.

@tisonkun tisonkun added this to the 3.1.0 milestone Jun 30, 2023
@tisonkun
Copy link
Member

/pulsarbot run-failure-checks

Copy link
Contributor

@nicoloboschi nicoloboschi left a comment

Choose a reason for hiding this comment

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

LGTM

@tisonkun
Copy link
Member

/pulsarbot run-failure-checks

@github-actions github-actions bot removed the Stale label Jul 1, 2023
@Technoboy- Technoboy- modified the milestones: 3.1.0, 3.2.0 Jul 31, 2023
@github-actions
Copy link

The pr had no activity for 30 days, mark with Stale label.

@github-actions github-actions bot added the Stale label Aug 31, 2023
@tisonkun
Copy link
Member

Merge the latest master and rerun...

@tisonkun
Copy link
Member

tisonkun commented Aug 31, 2023

Merging...

Thank you!

@tisonkun tisonkun merged commit f1c8684 into apache:master Aug 31, 2023
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-not-needed Your PR changes do not impact docs Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants