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

Viper and Cobra integration #51

Merged
merged 8 commits into from
Jan 23, 2019
Merged

Viper and Cobra integration #51

merged 8 commits into from
Jan 23, 2019

Conversation

jshencode
Copy link
Contributor

No description provided.

@jshencode jshencode changed the title Viper integration Viper and Cobra integration Jan 18, 2019
cmd/cmd.go Outdated
scope.Counter("restart").Inc(1)
serverRestartTimer := scope.Timer("restart").Start()

// Create MetaStore.
metaStorePath := filepath.Join(*rootPath, "metastore")
metaStorePath := filepath.Join(utils.GetConfig().RootPath, "metastore")
Copy link
Contributor

Choose a reason for hiding this comment

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

config is already passed in

@codecov-io
Copy link

codecov-io commented Jan 18, 2019

Codecov Report

Merging #51 into master will decrease coverage by 0.21%.
The diff coverage is 23.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #51      +/-   ##
==========================================
- Coverage   75.76%   75.54%   -0.22%     
==========================================
  Files          85       86       +1     
  Lines       13189    13253      +64     
==========================================
+ Hits         9992    10012      +20     
- Misses       2392     2435      +43     
- Partials      805      806       +1
Impacted Files Coverage Δ
utils/env.go 0% <0%> (ø) ⬆️
memstore/cuckoo_index.go 91.21% <100%> (ø) ⬆️
utils/di.go 43.33% <100%> (+14.16%) ⬆️
utils/config.go 8.82% <8.82%> (ø)
query/aql_postprocessor.go 68% <0%> (-4.35%) ⬇️
query/common/hll.go 67.91% <0%> (-3.04%) ⬇️
api/query_handler.go 77.55% <0%> (+6.51%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b67df47...c1ed469. Read the comment docs.

}

// ResetDefaults reset default config, logger and metrics settings
func ResetDefaults() {
logger = common.NewLoggerFactory().GetDefaultLogger()
queryLogger = common.NewLoggerFactory().GetDefaultLogger()
scope := tally.NewTestScope("test", nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

why test scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are default settings used in tests mostly

in production we set using utils.Init()

v.SetConfigFile(cfgFile)
} else {
v.SetConfigName("ares")
v.AddConfigPath("./config")
Copy link
Contributor

Choose a reason for hiding this comment

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

how about customized config path?

// AppParams contains application parameters for creating command
type AppParams struct {
DefaultCfg map[string]interface{}
ServerLogger bark.Logger
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can enhance this by checking ServerLogger, QueryLogger, Metrics is nil or not and set default accordingly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

cmd/cmd.go Outdated
DefaultCfg map[string]interface{}
ServerLogger bark.Logger
QueryLogger bark.Logger
Metrics common.Metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of using a big struct, probably we can use optional argument pattern here:
https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md
so user can specify what they want and leave defaults for remaining

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

cmd/cmd.go Outdated

loggerFactory := common.NewLoggerFactory()
if options.ServerLogger == nil {
options.ServerLogger = loggerFactory.GetDefaultLogger()
Copy link
Contributor

Choose a reason for hiding this comment

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

nits, we can create defaults during struct initialization:
like the example in the link did

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

utils/config.go Outdated
v.BindEnv("env")
}

// AddFlagsToCommand adds flags to command
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

utils/config.go Outdated
"os"
)

// BindenvsToViper binds environment variables to viper
Copy link
Contributor

Choose a reason for hiding this comment

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

nit function name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@jshencode jshencode merged commit 12a85b9 into master Jan 23, 2019
@jshencode jshencode deleted the viper-integration branch January 23, 2019 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants