Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactor entrypoint, parse config from env vars and file #1131

Merged
merged 5 commits into from
Jul 31, 2023

Conversation

lovromazgon
Copy link
Member

Description

This PR does two things:

  • It refactors the Conduit entrypoint and extracts it into pkg/conduit. We now provide a single function Serve that parses the config and runs Conduit (default behavior of the Conduit CLI). It takes a Config and uses the values from it as default values. If values are provided via flags, env variables or a config file, the default config values are overwritten. This allows us to easily create different Conduit distributions that are configured with different default values or contain different built-in plugins and processors, e.g.:

    func main() {
    	// start with the default Conduit config
    	cfg := conduit.DefaultConfig()
    	// output JSON logs by default
    	cfg.Log.Format = "json"
    	// bundle Mongo connector as a built-in connector
    	cfg.PluginDispenserFactories["mongo"] = builtin.NewDispenserFactory(mongo.Connector)
    	// register custom built-in processor
    	cfg.ProcessorBuilderRegistry.Register("custom", func(config processor.Config) (processor.Interface, error) { ... })
    	// start Conduit
    	conduit.Serve(cfg)
    }
  • We now use peterbourgon/ff to parse the CLI flags. This additionally allows us to parse the config from environment variables (lower priority) or a configuration file (lowest priority).

    • Env variables have the prefix CONDUIT and contain underscores instead of dots and hyphens (e.g. CONDUIT_DB_TYPE=postgres and CONDUIT_DB_POSTGRES_CONNECTION_STRING=postgres://localhost:5432/conduitdb).
    • The config file is by default named conduit.yaml and can be adjusted using the flag -config. The expected format is YAML and keys with dots can be hierarchically split, e.g.:
    db:
      type: postgres
      postgres:
        connection-string: postgres://localhost:5432/conduitdb

Fixes #31

Quick checks:

  • I have followed the Code Guidelines.
  • There is no other pull request for the same update/change.
  • I have written unit tests. (tested manually)
  • I have made sure that the PR is of reasonable size and can be easily reviewed.

@lovromazgon lovromazgon requested a review from a team as a code owner July 25, 2023 13:18
Copy link
Contributor

@hariso hariso left a comment

Choose a reason for hiding this comment

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

LGTM! It would be nice to see a word or two about this in the README.

@lovromazgon lovromazgon requested a review from hariso July 31, 2023 12:14
@lovromazgon
Copy link
Member Author

I added a part to the readme, @hariso can you have a look and let me know if it makes sense? 😉

@hariso
Copy link
Contributor

hariso commented Jul 31, 2023

I added a part to the readme, @hariso can you have a look and let me know if it makes sense? 😉

LGTM!

@lovromazgon lovromazgon merged commit 99d32f0 into main Jul 31, 2023
@lovromazgon lovromazgon deleted the lovro/entrypoint branch July 31, 2023 12:35
@simonl2002 simonl2002 added this to the 0.8.0 milestone Jul 31, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI configuration
3 participants