Skip to content

Commit

Permalink
Merge remote-tracking branch 'grafana/master' into package-scss
Browse files Browse the repository at this point in the history
* grafana/master:
  Explore: Adds support for toggling text edit mode in explore (grafana#17870)
  LDAP: Divide the requests (grafana#17885)
  Build: fixes missing shebang in release tagging script. (grafana#17894)
  Teams: show proper label for each auth provider (grafana#17860)
  Logging: Login and Logout logging actions (grafana#17760) (grafana#17883)
  Loki: Adds comment explaining usage of RFC3339Nano string (grafana#17872)
  Explore: Query rows are now reset when changing data sources (grafana#17865)
  Codestyle: add guidelines for removing the m alias for models (grafana#17890)
  Docs: How to work with themes (grafana#17876)
  Docs: Fix developing plugins index page (grafana#17877)
  StatsPicker: Fix multiple value input layout etc. (grafana#17827)
  Chore: Build grafana-cli when running bra run (grafana#17788)
  Build: use golangci-lint as a make command (grafana#17739)
  Explore: Log highlights only update when user stops typing (grafana#17845)
  Loki: getHighlighterExpressionsFromQuery Returns null if filter term is not quoted (grafana#17852)
  Docs upgrading deps (grafana#17657)
  Testing: Include BatchRevoke for all tokens in the fake. (grafana#17728)
  • Loading branch information
ryantxu committed Jul 3, 2019
2 parents f2167e4 + 98147fd commit 67a136e
Show file tree
Hide file tree
Showing 47 changed files with 713 additions and 175 deletions.
3 changes: 2 additions & 1 deletion .bra.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[run]
init_cmds = [
["go", "run", "build.go", "-dev", "build-server"],
["go", "run", "build.go", "-dev", "build-cli"],
["go", "run", "build.go", "-dev", "build-server"],
["./bin/grafana-server", "-packaging=dev", "cfg:app_mode=development"]
]
watch_all = true
Expand Down
32 changes: 16 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ jobs:
name: check documentation spelling errors
command: 'codespell -I ./words_to_ignore.txt docs/'

backend-lint:
lint-go:
docker:
- image: circleci/golang:1.12.6
environment:
Expand All @@ -124,8 +124,8 @@ jobs:
steps:
- checkout
- run:
name: backend lint
command: './scripts/backend-lint.sh'
name: Lint Go
command: 'make lint-go'

test-frontend:
docker:
Expand Down Expand Up @@ -633,7 +633,7 @@ workflows:
filters: *filter-only-master
- codespell:
filters: *filter-only-master
- backend-lint:
- lint-go:
filters: *filter-only-master
- test-frontend:
filters: *filter-only-master
Expand All @@ -649,7 +649,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
- build-oss-msi
Expand All @@ -661,7 +661,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-master
Expand All @@ -671,7 +671,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
- build-all-enterprise
Expand All @@ -682,7 +682,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-master
Expand All @@ -702,7 +702,7 @@ workflows:
filters: *filter-only-release
- codespell:
filters: *filter-only-release
- backend-lint:
- lint-go:
filters: *filter-only-release
- test-frontend:
filters: *filter-only-release
Expand All @@ -718,7 +718,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
- build-oss-msi
Expand All @@ -730,7 +730,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
Expand All @@ -741,7 +741,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
Expand All @@ -751,7 +751,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
Expand All @@ -769,7 +769,7 @@ workflows:
- build-fast-frontend
- codespell:
filters: *filter-not-release-or-master
- backend-lint:
- lint-go:
filters: *filter-not-release-or-master
- test-frontend:
filters: *filter-not-release-or-master
Expand All @@ -787,7 +787,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
- cache-server-test
Expand All @@ -798,7 +798,7 @@ workflows:
- test-backend
- test-frontend
- codespell
- backend-lint
- lint-go
- mysql-integration-test
- postgres-integration-test
- cache-server-test
Expand Down
31 changes: 23 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-include local/Makefile

.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go test-go test-js test run clean gosec revive devenv devenv-down revive-alerting
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go gosec revive golangci-lint go-vet test-go test-js test run clean devenv devenv-down revive-alerting

GO := GO111MODULE=on go
GO_FILES := ./pkg/...
Expand Down Expand Up @@ -43,10 +43,6 @@ build-docker-full:
@echo "build docker container"
docker build --tag grafana/grafana:dev .

lint-go:
@echo "lint go source"
scripts/backend-lint.sh

test-go:
@echo "test backend"
GO111MODULE=on go test -v ./pkg/...
Expand Down Expand Up @@ -78,27 +74,46 @@ scripts/go/bin/bra: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/bra github.com/Unknwon/bra

scripts/go/bin/golangci-lint: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint

revive: scripts/go/bin/revive
@echo "lint via revive"
@scripts/go/bin/revive \
-formatter stylish \
-config ./scripts/go/configs/revive.toml \
$(GO_FILES)

revive-alerting: scripts/go/bin/revive
@echo "lint alerting via revive"
@scripts/go/bin/revive \
-formatter stylish \
./pkg/services/alerting/...

run: scripts/go/bin/bra
@scripts/go/bin/bra run

# TODO recheck the rules and leave only necessary exclusions
gosec: scripts/go/bin/gosec
@echo "lint via gosec"
@scripts/go/bin/gosec -quiet \
-exclude=G104,G107,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json \
$(GO_FILES)

golangci-lint: scripts/go/bin/golangci-lint
@echo "lint via golangci-lint"
@scripts/go/bin/golangci-lint run \
--config ./scripts/go/configs/.golangci.yml \
$(GO_FILES)

go-vet:
@echo "lint via go vet"
@go vet $(GO_FILES)

lint-go: go-vet golangci-lint revive revive-alerting gosec

run: scripts/go/bin/bra
@scripts/go/bin/bra run

# create docker-compose file with provided sources and start them
# example: make devenv sources=postgres,openldap
ifeq ($(sources),)
Expand Down
18 changes: 15 additions & 3 deletions UPGRADING_DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,30 @@ The Grafana project uses [Go modules](https://golang.org/cmd/go/#hdr-Modules__mo

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:

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

# Pick a specific version.
go get example.com/some/module/[email protected]
GO111MODULE=on go get example.com/some/module/[email protected]
```

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

```bash
# 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.

## Node.js Dependencies

Updated using `yarn`.
Expand All @@ -60,7 +72,7 @@ Our builds run on CircleCI through our build script.

The main build step (in CircleCI) is built using a custom build container that comes pre-baked with some of the necessary dependencies.

Link: [grafana-build-container](https://github.com/grafana/grafana-build-container)
Link: [grafana/build-container](https://github.com/grafana/grafana/tree/master/scripts/build/ci-build)

#### Dependencies

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions packages/grafana-ui/src/components/Select/_Select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ $select-input-bg-disabled: $input-bg-disabled;
position: absolute;
z-index: $zindex-dropdown;
min-width: 100%;
&-notice--no-options {
background-color: $input-bg;
padding: 10px;
}
}

.gf-form-select-box__menu-list {
Expand All @@ -75,6 +79,21 @@ $select-input-bg-disabled: $input-bg-disabled;

.gf-form-select-box__multi-value {
display: inline;
margin: 0 6px 0 0;
cursor: pointer;
}

.gf-form-select-box__multi-value__remove {
text-align: center;
display: inline-block;
height: 14px;
vertical-align: middle;
margin-left: 2px;
}

.gf-form-select-box__multi-value__label {
display: inline;
vertical-align: middle;
}

.gf-form-select-box__option {
Expand Down Expand Up @@ -105,6 +124,7 @@ $select-input-bg-disabled: $input-bg-disabled;
vertical-align: middle;
> div {
display: inline-block;
vertical-align: middle;
}
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ We value clean & readable code that is loosely coupled and covered by unit tests
The majority of our tests uses go convey but thats something we want to avoid going forward.
For new tests we want to use standard library and `testify/assert`.

## Import aliases
Currently there are import aliases for `/pkg/models` package but thats something we want to avoid going forward.
Newly introduced code should refer explicitly to the `models` instead of using the alias `m`. Whenever changing existing code it's desired to remove the import aliases as well.

## The Bus
The bus is our way to introduce indirection between the HTTP handlers and sqlstore (responsible for fetching data from the database). Http handlers and sqlstore don't depend on each other. They only depend on the bus and the domain model(pkg/models). This makes it easier to test the code and avoids coupling. More about this under `current rewrite/refactorings`

Expand Down
30 changes: 1 addition & 29 deletions pkg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,4 @@ Newly introduced date columns in the database should be stored as epochs if date

# Dependency management

The Grafana project uses [Go modules](https://golang.org/cmd/go/#hdr-Modules__module_versions__and_more) 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:

```bash
# 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/[email protected]
```

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

```bash
# 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.


Documented in [UPDRAGING_DEPENDENCIES.md](https://github.com/grafana/grafana/blob/master/UPGRADING_DEPENDENCIES.md).
5 changes: 4 additions & 1 deletion pkg/STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ Grafanas backend has been developed for a long time with a mix of code styles.
This style guide is a guide for how we want to write Go code in the future. Generally, we want to follow the style guides used in Go [Code Review Comments](https://code.google.com/p/go-wiki/wiki/CodeReviewComments) and Peter Bourgon's [Go: Best Practices for Production Environments](http://peter.bourgon.org/go-in-production/#formatting-and-style)

## Linting and formatting
We enforce strict `gofmt` formating and use some linters on our codebase. You can find the current list of linters at https://github.com/grafana/grafana/blob/master/scripts/backend-lint.sh
We enforce strict `gofmt` formating and use some linters on our codebase. You can lint the codebase with <akefile -
```bash
$ make lint-go
```

We use [revive](https://github.com/mgechev/revive) as a go linter, and do enforce our [custom config](https://github.com/grafana/grafana/blob/master/conf/revive.toml) for it.

Expand Down
4 changes: 2 additions & 2 deletions pkg/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func (hs *HTTPServer) LoginPost(c *m.ReqContext, cmd dtos.LoginCommand) Response
}

metrics.M_Api_Login_Post.Inc()

return JSON(200, result)
}

Expand All @@ -139,7 +138,7 @@ func (hs *HTTPServer) loginUserWithUser(user *m.User, c *m.ReqContext) {
if err != nil {
hs.log.Error("failed to create auth token", "error", err)
}

hs.log.Info("Successful Login", "User", user.Email)
middleware.WriteSessionCookie(c, userToken.UnhashedToken, hs.Cfg.LoginMaxLifetimeDays)
}

Expand All @@ -153,6 +152,7 @@ func (hs *HTTPServer) Logout(c *m.ReqContext) {
if setting.SignoutRedirectUrl != "" {
c.Redirect(setting.SignoutRedirectUrl)
} else {
hs.log.Info("Successful Logout", "User", c.Email)
c.Redirect(setting.AppSubUrl + "/login")
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/pluginproxy/ds_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDSRouteRule(t *testing.T) {
},
}

setting.SecretKey = "password"
setting.SecretKey = "password" //nolint:goconst
key, _ := util.Encrypt([]byte("123"), "password")

ds := &m.DataSource{
Expand Down
Loading

0 comments on commit 67a136e

Please sign in to comment.