grafana/pkg
Marcus Efraimsson eecd8d1064 Elasticsearch: Visualize logs in Explore (#17605)
* explore: try to use existing mode when switching datasource

* elasticsearch: initial explore logs support

* Elasticsearch: Adds ElasticsearchOptions type
Updates tests accordingly

* Elasticsearch: Adds typing to query method

* Elasticsearch: Makes maxConcurrentShardRequests optional

* Explore: Allows empty query for elasticsearch datasource

* Elasticsearch: Unifies ElasticsearchQuery interface definition
Removes check for context === 'explore'

* Elasticsearch: Removes context property from ElasticsearchQuery interface
Adds field property
Removes metricAggs property
Adds typing to metrics property

* Elasticsearch: Runs default 'empty' query when 'clear all' button is pressed

* Elasticsearch: Removes index property from ElasticsearchOptions interface

* Elasticsearch: Removes commented code from ElasticsearchQueryField.tsx

* Elasticsearch: Adds comment warning usage of for...in to elastic_response.ts

* Elasticsearch: adds tests related to log queries
2019-06-24 21:15:03 +01:00
..
api Elasticsearch: Visualize logs in Explore (#17605) 2019-06-24 21:15:03 +01:00
bus Codestyle: Fix govet issues (#17178) 2019-06-04 22:00:05 +02:00
cmd Grafana-CLI: Wrapper for grafana-cli within RPM/DEB packages and config/homepath are now global flags (#17695) 2019-06-24 20:20:21 +01:00
components gtime: some code style refactoring (#17369) 2019-06-10 07:38:31 +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: remove gofakeit dep (#17344) 2019-05-29 15:55:51 +03:00
infra RemoteCache: redis connection string parsing test (#17702) 2019-06-24 11:51:38 +02:00
login LDAP: refactoring (#17479) 2019-06-13 16:47:51 +02:00
middleware middleware: fix Strict-Transport-Security header (#17644) 2019-06-18 14:24:23 -04:00
models SQLStore: extend user.SearchUsers method (#17514) 2019-06-14 09:50:38 +01:00
plugins Explore: Queries the datasource once per run query and uses DataStreamObserver (#17263) 2019-06-03 14:54:32 +02:00
registry add functionality to override service in registry 2018-10-30 13:37:30 +01:00
services LDAP: small improvements to various LDAP parts (#17662) 2019-06-19 15:46:04 +02:00
setting config: fix connstr for remote_cache (#17675) 2019-06-20 10:15:21 -04:00
tsdb Prometheus: Preallocate data for Prometheus backend response parsing (#17490) 2019-06-10 08:12:46 +02:00
util CLI: Add command to migrate all datasources to use encrypted password fields (#17118) 2019-05-27 10:47:21 +02:00
ARCHITECTURE.md codestyle: styleguide and arch for grafanas backend (#17545) 2019-06-18 09:31:51 +02:00
README.md Add guidelines for SQL date comparisons (#17732) 2019-06-24 20:39:28 +03:00
STYLEGUIDE.md codestyle: styleguide and arch for grafanas backend (#17545) 2019-06-18 09:31:51 +02:00

Grafana backend codebase

The code styleguide and brief description of the architecture

On going refactorings.

These issues are not something we want to address all at once but something we will improve over time. Since Grafana is released at a regular schedule the prefer approuch is to do this in batches. Not only is it easier to review, it also reduces the risk of conflicts when cherry-picking fixes from master to release branches. Changes that spawn multiple locations are therefore prefered in the end of the release cycle since we make fewer patch releases in the end of the cycle.

Global state

Global state makes testing and debugging software harder and its something we want to avoid when possible. Unfortunately, there is quite a lot of global state in Grafana. The way we want to migrate away from this is to use 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

Reduce the use of the init() function

Should only be used 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/components can inject this setting.Cfg struct.

Cfg struct Injection example

Reduce the use of Goconvey

We want to migrated away from using Goconvey and use stdlib testing as its the most common approuch in the GO community and we think it will make it easier for new contributors. Read more about how we want to write tests in the ARCHITECTURE.MD docs.

Sqlstore refactoring

The sqlstore handlers all use a global xorm engine variable. This should be refactored to use the Sqlstore instance.

Avoid global HTTP Handler functions

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

Date comparison

Newly introduced date columns in the database should be stored as epochs if date comparison is required. This permits to have a unifed approach for comparing dates against all the supported databases instead of handling seperately each one of them. In addition to this, by comparing epochs error pruning transformations from/to other time zones are no more needed.

Dependency management

The Grafana project uses Go modules to manage dependencies on external packages. This requires a working Go environment with version 1.11 or greater installed.

All dependencies are vendored in the vendor/ directory.

Note: Since most developers of Grafana still use the GOPATH we need to specify GO111MODULE=on to make go mod and got get work as intended. If you have setup Grafana outside of the GOPATH on your machine you can skip GO111MODULE=on when running the commands below.

To add or update a new dependency, use the go get command:

# The GO111MODULE variable can be omitted when the code isn't located in GOPATH.
# Pick the latest tagged release.
GO111MODULE=on go get example.com/some/module/pkg

# Pick a specific version.
GO111MODULE=on go get example.com/some/module/pkg@vX.Y.Z

Tidy up the go.mod and go.sum files and copy the new/updated dependency to the vendor/ directory:

# The GO111MODULE variable can be omitted when the code isn't located in GOPATH.
GO111MODULE=on go mod tidy

GO111MODULE=on go mod vendor

You have to commit the changes to go.mod, go.sum and the vendor/ directory before submitting the pull request.