애니리뷰

고급컴퓨터현장실습 대비3) @grafana /toolkit 번역

두원공대88학번뚜뚜 2022. 10. 31. 14:04

@grafana/toolkit - npm (npmjs.com)

 

@grafana/toolkit

Grafana Toolkit. Latest version: 9.2.2, last published: 6 days ago. Start using @grafana/toolkit in your project by running `npm i @grafana/toolkit`. There is 1 other project in the npm registry using @grafana/toolkit.

www.npmjs.com

원문


grafana-toolkit

Grafana 플러그인을 효율적으로 개발할 수 있는 CLI.

Getting started

grafana-toolkit plugin:create를 이용해서, 새로운 플러그인을 설치한다.

npx @grafana/toolkit plugin:create my-grafana-plugin
cd my-grafana-plugin
yarn install
yarn dev

 

Note : 만약 NPM 7+가 실행중이라면, 해당 article에서 설명한 npx 커맨드가 행업되는 경우가 있다. 해결법은 npx --legacy-peer-deps <command to run>

Update your plugin to use grafana-toolkit

기존 플러그인에서 grafana-toolkit을 사용하기 위해서 아래의 step을 따르시오.

  1. yarn add @grafana/toolkit or npm install @grafana/toolkit을 실행하여 현 프로젝트에 @grafana/toolkit package를 추가하자.
  2. Create tsconfig.json파일을 plugin의 루트 디렉토리에 생성하고, 아래의 코드를 복붙 
{
  "extends": "./node_modules/@grafana/toolkit/src/config/tsconfig.plugin.json",
  "include": ["src", "types"],
  "compilerOptions": {
    "rootDir": "./src",
    "baseUrl": "./src",
    "typeRoots": ["./node_modules/@types"]
  }
}
  1. .prettierrc.js을 플러그인의 루트 디렉토리에 생성하고, 아래의 코드를 복붙
module.exports = {
  ...require('./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json'),
};
  1.  package.json파일에 아래 스크립트를 추가:
"scripts": {
  "build": "grafana-toolkit plugin:build",
  "test": "grafana-toolkit plugin:test",
  "dev": "grafana-toolkit plugin:dev",
  "watch": "grafana-toolkit plugin:dev --watch"
},

Usage

grafana-toolkit에서는, Grafana 플러그인에서 작업할 때 수행되는 일반적인 작업에 대응하는 CLI를 제공:

  • grafana-toolkit plugin:create
  • grafana-toolkit plugin:dev
  • grafana-toolkit plugin:test
  • grafana-toolkit plugin:build
  • grafana-toolkit plugin:sign

Create your plugin

grafana-toolkit plugin:create plugin-name

해당 명령어는 템플릿에서 새로운 Grafana 플러그인을 생성.

This command creates a new Grafana plugin from template.

If plugin-name를 작성시, ./plugin-name 디렉토리로 템플릿이 다운됨. 안 적어 내면, 현 디렉토리에 다운로드 됨.

Develop your plugin

grafana-toolkit plugin:dev

이 커맨드는 일반적인 브라우저 도구를 사용해 쉽게 플레이 및 디버깅할 수 있는 개발빌드 생성.

  • -w, --watch - 개발태스크를 watch mode로 실행

Test your plugin

grafana-toolkit plugin:test

코드베이스에 대해 Jest를 실행.

사용가능한 옵션:

Build your plugin

grafana-toolkit plugin:build

해당 명령어는, 플러그인의 실제 가동가능한 빌드를 생성.

사용 가능한 옵션:

  • --skipTest - 빌드의 일부로 테스트 실행을 스킵함. 대규모 파이프라인의 일부로 빌드를 실행하는 경우에 유용.
  • --skipLint - 빌드의 일부로 린트(오류, 의심스러운 곳을 표시하는 도구)를 스킵함. 대규모 파이프라인의 일부로 빌드를 실행하는 경우에 유용
  • --coverage - 코드 적용범위를 빌드 단계 테스트 후에 보고함.
  • --preserveConsole - 코드 내 콘솔문(console statements)을 유지

Sign your plugin

grafana-toolkit plugin:sign

해당 명령어는, Grafana가 플러그인의 무결성을 검증하기 위해 사용하는, 서명된 MANIFEST.txt 파일을 생성함.

사용가능 options:

  • --signatureType - 생성중인 서명의 유형. private, community or commercial
  • --rootUrls - 프라이빗 서명의 경우, 플러그인이 사용될 그라파나 인스턴스 url 목록.

signature(서명)을 생성하기 위해, https://grafana.com에서 계정을 생성하고 플러그인 퍼블리셔 role로 API키를 만들고 이를 GRAFANA_API_KEY 환경변수에 전달해야 함.