一、开发环境配置流程

1、基本环境

  • go版本:15+

  • nodejs:14+

  • grafana:7.5.10

  • gcc:win64 (下载并配置环境变量)

2、下载源码

3、设置环境代理

  • GOPROXY:https://mirrors.aliyun.com/goproxy/

  • NPM:--registry=https://registry.npm.taobao.org

  • 安装Yarn:npm install -g yarn

  • 配置Yarn源:yarn config set registry https://registry.npm.taobao.org

4、后端编译

  • go run build.go setup

  • go run build.go build(生成bin/windows-amd64/grafana-server.exe)

  • 命令行运行后端:bin/windows-amd64/grafana-server.exe

5、前端编译

  • yarn config set PUPPETEER_SKIP_CHROMIUM_DOWNLOAD 1

  • npm install node-gyp

  • yarn install --pure-lockfile(报错,无法获取react-use-measure,暂时把package.json中的resolution位置的react-use-measure删除)

修改前

"resolutions": { "caniuse-db": "1.0.30000772", "react-use-measure": "https://github.com/mckn/react-use-measure.git#remove-cjs-export" },`

修改后

"resolutions": { "caniuse-db": "1.0.30000772" }, `

  • 启动前端:yarn start(报错Error: Failed to load config "react-app" to extend from.不影响)

  • 访问localhost:3000

6、其他踩坑记录

  • iframe嵌入grafana:需要添加/修改配置([security]下的allow_embedding = true,cookie_samesite = none。allow_embedding表示允许嵌入iframe,cookie_samesite解决跨域设置set-cookies的问题)

    SameSite 属性 Cookie 的SameSite属性用来限制第三方 Cookie,从而减少安全风险。

    Strict、Lax、None

  • win10的Chrome(版本号:72.0.3626.119)可以登录,win7表现为循环登录

    cookie_samesite设置为disabled,但嵌套在iframe中的grafana仍表现为循环登录

二、编译配置

1、修改配置

修改文件conf/default.ini配置app_mode = production

2、编辑编译配置

Package path:github.com/grafana/grafana/pkg/cmd/grafana-server

Go tool arguments:-buildmode=exe

Program arguments:--config=conf/defaults.ini

3、执行调试

三、参考文档(官方)

# Developer guide
​
This guide helps you get started developing Grafana.
​
Before you begin, you might want to read [How to contribute to Grafana as a junior dev](https://medium.com/@ivanahuckova/how-to-contribute-to-grafana-as-junior-dev-c01fe3064502) by [Ivana Huckova](https://medium.com/@ivanahuckova).
​
## Dependencies
​
Make sure you have the following dependencies installed before setting up your developer environment:
​
- [Git](https://git-scm.com/)
- [Go](https://golang.org/dl/) (see [go.mod](../go.mod#L3) for minimum required version)
- [Node.js (Long Term Support)](https://nodejs.org)
- [Yarn](https://yarnpkg.com)
​
### macOS
​
We recommend using [Homebrew](https://brew.sh/) for installing any missing dependencies:
​
```
brew install git
brew install go
brew install node@14
​
npm install -g yarn
```
​
### Windows
​
If you are running Grafana on Windows 10, we recommend installing the Windows Subsystem for Linux (WSL). For installation instructions, refer to the [Microsoft WSL Installation Guide](https://docs.microsoft.com/en-us/windows/wsl/install-win10).
​
## Download Grafana
​
We recommend using the Git command-line interface to download the source code for the Grafana project:
​
1. Open a terminal and run `git clone https://github.com/grafana/grafana.git`. This command downloads Grafana to a new `grafana` directory in your current directory.
1. Open the `grafana` directory in your favorite code editor.
​
For alternative ways of cloning the Grafana repository, please refer to [GitHub's cloning a repository](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) documentation.
​
**Warning:** Do not use `go get` to download Grafana. Recent versions of Go have added behavior which isn't compatible with the way the Grafana repository is structured.
​
## Build Grafana
​
Grafana consists of two components; the _frontend_, and the _backend_.
​
### Frontend
​
Before we can build the frontend assets, we need to install the dependencies:
​
```
yarn install --pure-lockfile
```
​
After the command has finished, we can start building our source code:
​
```
yarn start
```
​
Once `yarn start` has built the assets, it will continue to do so whenever any of the files change. This means you don't have to manually build the assets every time you change the code.
​
Next, we'll build the web server that will serve the frontend assets we just built.
​
### Backend
​
Build and run the backend by running `make run` in the root directory of the repository. This command compiles the Go source code and starts a web server.
​
> Are you having problems with [too many open files](#troubleshooting)?
​
By default, you can access the web server at `http://localhost:3000/`.
​
Log in using the default credentials:
​
| username | password |
| -------- | -------- |
| `admin`  | `admin`  |
​
When you log in for the first time, Grafana asks you to change your password.
​
#### Building on Windows
​
The Grafana backend includes SQLite which requires GCC to compile. So in order to compile Grafana on Windows you need to install GCC. We recommend [TDM-GCC](http://tdm-gcc.tdragon.net/download). Eventually, if you use [Scoop](https://scoop.sh), you can install GCC through that.
​
You can simply build the back-end as follows: `go run build.go build`. The Grafana binaries will be in bin\\windows-amd64.
Alternately, if you wish to use the `make` command, install [Make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm) and use it in a Unix shell (f.ex. Git Bash).
​
## Test Grafana
​
The test suite consists of three types of tests: _Frontend tests_, _backend tests_, and _end-to-end tests_.
​
### Run frontend tests
​
We use [jest](https://jestjs.io/) for our frontend tests. Run them using Yarn:
​
```
yarn test
```
​
### Run backend tests
​
If you're developing for the backend, run the tests with the standard Go tool:
​
```
go test -v ./pkg/...
```
​
#### On Windows
​
Running the backend tests on Windows currently needs some tweaking, so use the build.go script:
​
```
go run build.go test
```
​
### Run end-to-end tests
​
The end to end tests in Grafana use [Cypress](https://www.cypress.io/) to run automated scripts in a headless Chromium browser. Read more about our [e2e framework](/contribute/style-guides/e2e.md).
​
To run the tests:
​
```
yarn e2e
```
​
By default, the end-to-end tests starts a Grafana instance listening on `localhost:3001`. To use a specific URL, set the `BASE_URL` environment variable:
​
```
BASE_URL=http://localhost:3333 yarn e2e
```
​
To follow the tests in the browser while they're running, use the `yarn e2e:debug`.
​
```
yarn e2e:debug
```
​
If you want to pick a test first, use the `yarn e2e:dev`, to pick a test and follow the test in the browser while it runs.
​
```
yarn e2e:dev
```
​
## Configure Grafana for development
​
The default configuration, `defaults.ini`, is located in the `conf` directory.
​
To override the default configuration, create a `custom.ini` file in the `conf` directory. You only need to add the options you wish to override.
​
Enable the development mode, by adding the following line in your `custom.ini`:
​
```
app_mode = development
```
​
### Add data sources
​
By now, you should be able to build and test a change you've made to the Grafana source code. In most cases, you need to add at least one data source to verify the change.
​
To set up data sources for your development environment, go to the [devenv](/devenv) directory in the Grafana repository:
​
```
cd devenv
```
​
Run the `setup.sh` script to set up a set of data sources and dashboards in your local Grafana instance. The script creates a set of data sources called **gdev-\<type\>**, and a set of dashboards located in a folder called **gdev dashboards**.
​
Some of the data sources require databases to run in the background.
​
Installing and configuring databases can be a tricky business. Grafana uses [Docker](https://docker.com) to make the task of setting up databases a little easier. Make sure you [install Docker](https://docs.docker.com/docker-for-mac/install/) before proceeding to the next step.
​
In the root directory of your Grafana repository, run the following command:
​
```
make devenv sources=influxdb,loki
```
​
The script generates a Docker Compose file with the databases you specify as `sources`, and runs them in the background.
​
See the repository for all the [available data sources](/devenv/docker/blocks). Note that some data sources have specific Docker images for macOS, e.g. `nginx_proxy_mac`.
​
## Build a Docker image
​
To build a Docker image, run:
​
```
make build-docker-full
```
​
The resulting image will be tagged as grafana/grafana:dev.
​
> **Note:** If you've already set up a local development environment, and you're running a `linux/amd64` machine, you can speed up building the Docker image:
​
1. Build the frontend: `go run build.go build-frontend`.
1. Build the Docker image: `make build-docker-dev`.
​
**Note:** If you are using Docker for macOS, be sure to set the memory limit to be larger than 2 GiB. Otherwise, `grunt build` may fail. The memory limit settings are available under **Docker Desktop** -> **Preferences** -> **Advanced**.
​
## Troubleshooting
​
Are you having issues with setting up your environment? Here are some tips that might help.
​
### Too many open files when running `make run`
​
Depending on your environment, you may have to increase the maximum number of open files allowed. For the rest of this section, we will assume you are on a Unix like OS (e.g. Linux/macOS), where you can control the maximum number of open files through the [ulimit](https://ss64.com/bash/ulimit.html) shell command.
​
To see how many open files are allowed, run:
​
```
ulimit -a
```
​
To change the number of open files allowed, run:
​
```
ulimit -S -n 2048
```
​
The number of files needed may be different on your environment. To determine the number of open files needed by `make run`, run:
​
```
find ./conf ./pkg ./public/views | wc -l
```
​
Another alternative is to limit the files being watched. The directories that are watched for changes are listed in the `.bra.toml` file in the root directory.
​
To retain your `ulimit` configuration, i.e. so it will be remembered for future sessions, you need to commit it to your command line shell initialization file. Which file this will be depends on the shell you are using, here are some examples:
​
- zsh -> ~/.zshrc
- bash -> ~/.bashrc
​
Commit your ulimit configuration to your shell initialization file as follows ($LIMIT being your chosen limit and $INIT_FILE being the initialization file for your shell):
​
```
echo ulimit -S -n $LIMIT >> $INIT_FILE
```
​
Your command shell should read the initialization file in question every time it gets started, and apply your `ulimit` command.
​
For some people, typically using the bash shell, ulimit fails with an error similar to the following:
​
```
ulimit: open files: cannot modify limit: Operation not permitted
```
​
If that happens to you, chances are you've already set a lower limit and your shell won't let you set a higher one. Try looking in your shell initialization files (~/.bashrc typically), if there's already a ulimit command that you can tweak.
​
## Next steps
​
- Read our [style guides](/contribute/style-guides).
- Learn how to [Create a pull request](/contribute/create-pull-request.md).
- Read [How to contribute to Grafana as a junior dev](https://medium.com/@ivanahuckova/how-to-contribute-to-grafana-as-junior-dev-c01fe3064502) by [Ivana Huckova](https://medium.com/@ivanahuckova).
- Read about the [architecture](architecture).

grafana开发与调试相关推荐

  1. NDK JNI Android Studio开发与调试DEMO(三)(生成 .so 文件)

    Android Studio NDK 开发与调试(生成 .so 文件) 温馨提示:如果你的 Android Studio 版本在 3.0以上 , 建议你用 cMake /ndk-build 的新姿势进 ...

  2. 使用Visual Studio 2010开发和调试Html5项目

    上周有幸参加微软技术大会(TechED2010),身临其境领略微软这样的国际化公司大家风范,云加端的概念将技术思维提到的一个新的档次,此行收获很大,在第一天谢恩伟提到正在进行的IE9开发大赛让我很是关 ...

  3. Python中str()与repr()函数的区别——repr() 的输出追求明确性,除了对象内容,还需要展示出对象的数据类型信息,适合开发和调试阶段使用...

    Python中str()与repr()函数的区别 from:https://www.jianshu.com/p/2a41315ca47e 在 Python 中要将某一类型的变量或者常量转换为字符串对象 ...

  4. linux 内核启动调试,内核开发和调试的启动时参数

    内核开发和调试的启动时参数 这些参数主要用在内核的开发和调试上,如果你不进行类似的工作,你可以简单的跳过本小节. 1.debug linux的日志级别比较多(详细信息可以参看linux/kernel. ...

  5. 使用VS Code 从零开始开发并调试.NET Core 应用程序

    使用VS Code 从零开始开发并调试.NET Core 应用程序,C#调试.上一篇 使用VS Code开发 调试.NET Core 应用程序 得到了大家的支持. 现在为大家带来从零开始教程,让你更好 ...

  6. Android开发和调试必备工具-SDK Tools

    原文链接:http://android.eoe.cn/topic/android_sdk SDK Tools是Android SDK的一个可下载部分,它包括Android SDK的开发和调试的所有工具 ...

  7. tomcat开发远程调试端口以及利用eclipse进行远程调试

    一.tomcat开发远程调试端口 方法1 WIN系统 在catalina.bat里:  SET CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compi ...

  8. 使用Android Studio 进行NDK开发和调试

    2019独角兽企业重金招聘Python工程师标准>>> 尽管Android Studio已经越来越流行了,但很多人还是习惯于Eclipse或源码环境下开发JNI应用.个人认为使用An ...

  9. 鸿蒙系统-手机-HAP开发编译调试

    鸿蒙系统-手机-HAP开发编译调试 1.开发环境 环境搭建请看 https://developer.harmonyos.com/cn/docs/documentation/doc-guides/ins ...

最新文章

  1. V3S中默认时区设置(笔记)
  2. 我的世界boat运行库JAVA10_我的世界boatmod模组大全
  3. luogu P1231 教辅的组成
  4. 头部数据人才24小时图鉴
  5. 【Python数据挖掘课程】四.决策树DTC数据分析及鸢尾数据集分析
  6. linux重装出现cannot load file 5555h,重装win7系统开机提示cannot load file code:5555h怎么办...
  7. javascrpt --- 使用jquery添加dom元素和Angular ng-repeat生成select性能比较
  8. 移动端上传大文件到服务器,android上传大文件到服务器地址
  9. 计算机网络学习笔记(10. 速率、带宽、延迟)
  10. Could not find artifact com.taotao:taotao-parent:pom原因
  11. tar打包时忽略svn目录
  12. 【离散数学】相关概念_01
  13. 微信小程序 Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded(二)
  14. **Unity环境光遮蔽(Ambient Occlusion)Shader实现逻辑**
  15. c语言wakeup函数,关于RTC时钟RTC_Set_WakeUp(u32 wksel,u16 cnt)函数的疑惑
  16. ANSYS APDL 绘制云图时出现错误“The Requested S data is not available. The PLNSOL command is ignored“的解决方法
  17. SaltStack之return与job管理
  18. 电脑如何批量下载哔哔视屏_我是电脑哔哔哔哔哔
  19. JVM--藤原豆腐店自用
  20. 实验二 单隐层神经网络

热门文章

  1. 比肩犀牛书的《JavaScript编程精》原书第3版(中文版)重磅来袭!文末福利
  2. java session 生命周期_Java架构师第十四步——Session的生命周期(读书笔记)
  3. Windows系统鲜为人知的宝藏
  4. Linux后台开发系列之「11.IO 概述」
  5. 一款Android App升级库
  6. Android R system_ext动态扩展分区
  7. NCRE - 嵌入式系统开发工程师 – 操作系统(随笔)
  8. 三菱FX3U与3台三菱e740或D700变频器通讯程序 三菱FX3U与3台三菱变频器 modbus RTU通讯案例
  9. 视频号的特征以及视频号的5大关键:国仁楠哥
  10. 【转载自amobbs IDzhcj66】FATFS读取数据问题