grafana/pkg
Marcus Olsson 428ca600c0
Chore: Refactor grafana-server (#19796)
* Rename GrafanaServerImpl to Server

* Make flag dependencies explicit

* Extract method for building service graph

* Document and clarify methods

* Rename HttpServer to HTTPServer
2019-10-14 14:18:22 +02:00
..
api Datasource: Add custom headers on alerting queries (#19508) 2019-10-11 14:28:52 +02:00
bus Codestyle: Fix govet issues (#17178) 2019-06-04 22:00:05 +02:00
cmd Chore: Refactor grafana-server (#19796) 2019-10-14 14:18:22 +02:00
components pkg/components: Check errors (#19703) 2019-10-10 09:06:55 +02:00
events feat(signup): progress on new sign up and email verification flow, #2353 2015-08-28 15:14:24 +02:00
extensions Enterprise: add dependencies for upcoming features (#18793) 2019-08-30 18:14:32 +02:00
infra pkg/infra: Check errors (#19705) 2019-10-10 16:42:11 +02:00
login pkg/login: Check errors (#19714) 2019-10-09 12:57:44 +02:00
middleware LDAP: Add API endpoint to debug user mapping from LDAP (#18833) 2019-09-03 18:34:44 +01:00
models Datasource: Add custom headers on alerting queries (#19508) 2019-10-11 14:28:52 +02:00
plugins pkg/plugins: Check errors (#19715) 2019-10-11 21:02:15 +02:00
registry add functionality to override service in registry 2018-10-30 13:37:30 +01:00
services fix: export Bus on search service (#19773) 2019-10-11 11:46:44 -04:00
setting Upgrade grafana-plugin-model (#19438) 2019-09-30 15:16:04 +02:00
tsdb Datasource: Add custom headers on alerting queries (#19508) 2019-10-11 14:28:52 +02:00
util Don't truncate IPv6 addresses (#19573) 2019-10-09 08:58:45 +02:00
ARCHITECTURE.md Docs: Minor edits to the README and several md files (#19238) 2019-09-20 00:04:56 +02:00
README.md Docs: Update pkg\README.md (#19615) 2019-10-09 08:04:56 +02:00

Grafana backend codebase

The code should follow the Backend style guide.

Refer to architecture for a description of the backend codebase architecture.

Ongoing refactoring

These issues are not something we want to address all at once but something we will improve incrementally. Since Grafana is released at a regular schedule the preferred approach is to do this in batches. Not only is it easier to review, but it also reduces the risk of conflicts when cherry-picking fixes from master to release branches. Please try to submit changes that span multiple locations at the end of the release cycle. We prefer to wait until the end because we make fewer patch releases at the end of the release cycle, so there are fewer opportunities for complications.

Global state

Global state makes testing and debugging software harder and it's something we want to avoid when possible. Unfortunately, there is quite a lot of global state in Grafana.

We want to migrate away from this by using the inject package to wire up all dependencies either in pkg/cmd/grafana-server/main.go or self-registering using registry.RegisterService ex https://github.com/grafana/grafana/blob/master/pkg/services/cleanup/cleanup.go#L25.

Limit the use of the init() function

Only use the init() function to register services/implementations.

Settings refactoring

The plan is to move all settings to from package level vars in settings package to the setting.Cfg struct. To access the settings, services and components can inject this setting.Cfg struct:

Cfg struct Injection example

Reduce the use of GoConvey

We want to migrate away from using GoConvey. Instead, we want to use stdlib testing, because it's the most common approach in the Go community and we think it will be easier for new contributors. Read more about how we want to write tests in ARCHITECTURE.MD.

Refactor SqlStore

The sqlstore handlers all use a global xorm engine variable. Refactor them to use the SqlStore instance.

Avoid global HTTP handler functions

Refactor HTTP handlers so that the handler methods are on the HttpServer instance or a more detailed handler struct. E.g (AuthHandler). This ensures they get access to HttpServer service dependencies (and Cfg object) and can avoid global state.

Date comparison

Store newly introduced date columns in the database as epochs if they require date comparison. This permits a unified approach for comparing dates against all the supported databases instead of handling dates differently for each database. Also, by comparing epochs, we no longer need error pruning transformations to and from other time zones.

Dependency management

Refer to UPGRADING_DEPENDENCIES.md.