Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

code cleanup and refactor #1031

Closed
woodsaj opened this issue Aug 31, 2018 · 8 comments
Closed

code cleanup and refactor #1031

woodsaj opened this issue Aug 31, 2018 · 8 comments

Comments

@woodsaj
Copy link
Member

woodsaj commented Aug 31, 2018

There are a number of code cleanup initiatives we want to tackle. Config, logging, plugin management.

The plugin-management changes are needed so that we can build metrictank-enterprise versions with more advanced input, index and store plugins (plus any other future features we want to add).

To be able to do that, we need to overhaul how we initialize and share components/plugins.

I have been looking at the Grafana code base and I really like what they have done with self-registering components and dependency injection. I think that is the model we should follow.

I have built a basic POC of how all of the capabilities work together. I have tried to cover all of the use cases that we have in Metrictank. The highlights are:

Trying to update everything to match this architecture in one go is going to be a huge PR, that would be hard to review. But i think we should be able to transition to this architecture in small steps.

The most impactful change is going to be updating how we manage configuration. I have really come to like github.com/spf13/viper. Viper doesnt work with INI files, so would need to move to json or yaml. But otherwise i think we can keep the same config names and ENV vars.

@Dieterbe
Copy link
Contributor

Dieterbe commented Sep 3, 2018

Viper doesnt work with INI files, so would need to move to json or yaml

viper supports toml, which is basically a more formally defined (standardized) implementation of ini files.
I think ini (toml) is pretty great, and json/yaml are not a good fit for configs (too extensive).
if we could transition to a better config library such as viper, while keeping compatibility with current config files and env vars (and override rules between them) that would be great.

@woodsaj
Copy link
Member Author

woodsaj commented Sep 4, 2018

I agree that json isn't pleasant to work with. But yaml can be fine, depending on how you layout the file.

The thing I like most about viper is that it normalizes the config variable names for you.
eg the yaml

---
cassandra:
  addrs: localhost
  consistency: one

is the same as the yaml

---
cassandra.addrs: localhost
cassandra.consistancy: one

which is the same as the toml

[cassandra]
addrs = "localhost"
consistency = "one"

I have played around with trying to get viper to parse an ini file. you cant just treat the ini file as a toml file, as ini does not require strings to be quoted, but toml does.
But i have been successfull in loading in an inifile, then writing it to a buffer as a yaml file, then loading that into viper. Seems to work without issue. see woodsaj/go-server#1

So it looks like we should be able to support a transition period where we expect the ini file format by default, but also allow users to use toml, yaml or json by passing a cmdline flag. Then after the transition period we default to using toml, yaml or json and make ini optional via the cmdline flag. And eventually drop support for ini.

@woodsaj
Copy link
Member Author

woodsaj commented Sep 4, 2018

@Dieterbe if you are happy with the architecture changes proposed here, then i think we can formulate a plan of attack. I am thinking we should make the following changes, in this order

  • move to logrus for logging.
  • refactor to use Viper, keeping the current ini config.
    • replace the "ConfigSetup()" funcs in packages with an "init()" that sets defaults.
    • instead of using package variables for config settings, we just get them from viper when needed via viper.GetBool(), viper.GetString(), etc...
    • rename the "ConfigProcess()" funcs to "Init()", inline with our future component registry.
  • Add the registry and start moving components to it. Moving all components to the registry would be done over a few PRs

@Dieterbe
Copy link
Contributor

Dieterbe commented Sep 4, 2018

haven't had time yet to look into all of the architecture changes, but we can start with the switch to logrus (#624)

@Dieterbe
Copy link
Contributor

Dieterbe commented Sep 6, 2018

some prior discussion re config in #456

@Dieterbe
Copy link
Contributor

realistically I won't be able to give this the attention it needs for at least another week of 2,
due to various operational issues . is that a problem? are we blocked on this?

@Dieterbe
Copy link
Contributor

came across https://blog.golang.org/wire
if it's not too complicated, looks like an interesting alternative over inject

@stale
Copy link

stale bot commented Jun 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 7, 2020
@stale stale bot closed this as completed Jun 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants