Skip to content

Commit

Permalink
frontend: apply prettier to cypress/webapp (grafana#417)
Browse files Browse the repository at this point in the history
* frontend: add husky + lint-staged

idea here is to run eslint + prettier
against staged files
so that nothing broken is pushed

frontend: add cypress eslint plugin

frontend: reformat more files

* set correct git blame rev

* don't assume npx is installed

* run prettier checks in ci

* add prettier/react rules to eslint

* also format .eslintrc

* reformat python docker-compose

Co-authored-by: Dmitry Filimonov <[email protected]>
  • Loading branch information
eh-am and petethepig authored Sep 24, 2021
1 parent ec880c5 commit fffac60
Show file tree
Hide file tree
Showing 123 changed files with 2,431 additions and 1,689 deletions.
6 changes: 2 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"build": { "dockerfile": "Dockerfile" },
"extensions": [
"golang.go"
],
"forwardPorts": [4040]
"extensions": ["golang.go"],
"forwardPorts": [4040]
}
20 changes: 13 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"parser": "babel-eslint",
"plugins": ["prettier"],
"extends": ["airbnb", "prettier"],
"extends": [
"airbnb",
"prettier",
"prettier/react",
"plugin:cypress/recommended"
],
"rules": {
"import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
"no-unused-vars": ["warn"],
"prettier/prettier": ["error"],
"no-param-reassign": ["warn"],
"no-shadow": ["warn"],
"no-case-declarations": ["warn"],
Expand All @@ -16,15 +20,17 @@
"jsx-a11y/heading-has-content": ["warn"],
"jsx-a11y/control-has-associated-label": ["warn"],
"no-undef": ["warn"],
"react/jsx-one-expression-per-line": ["warn"],
"jsx-a11y/mouse-events-have-key-events": ["warn"],
"jsx-a11y/click-events-have-key-events": ["warn"],
"jsx-a11y/no-static-element-interactions": ["warn"],
"jsx-a11y/label-has-associated-control": [ "error", {
"required": {
"some": [ "nesting", "id" ]
"jsx-a11y/label-has-associated-control": [
"error",
{
"required": {
"some": ["nesting", "id"]
}
}
}]
]
},
"env": {
"browser": true,
Expand Down
1 change: 1 addition & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fca0fcf152cb304c10b94bd3b78d56a319485170
2 changes: 1 addition & 1 deletion .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
uses: petethepig/revive-action@v5
with:
config: revive.toml
exclude: "vendor/..."
exclude: 'vendor/...'
11 changes: 5 additions & 6 deletions .github/workflows/lint-markdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ name: Markdown Linting
# runs every monday at 9 am
on:
schedule:
- cron: "0 9 * * 1"
- cron: '0 9 * * 1'

jobs:
markdown-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: .github/workflows/markdown-links-config.json

- uses: actions/checkout@v2
- uses: gaurav-nelson/github-action-markdown-link-check@v1
with:
config-file: .github/workflows/markdown-links-config.json
2 changes: 2 additions & 0 deletions .github/workflows/tests-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ jobs:
run: yarn run test
- name: Run Webapp lints
run: yarn lint
- name: Run Webapp Format check
run: yarn format:check
22 changes: 11 additions & 11 deletions .github/workflows/update-contributos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: Install dependencies
run: make install-web-dependencies
- name: Install dependencies
run: make install-web-dependencies

- name: Update contributors
run: make update-contributors
- name: Update contributors
run: make update-contributors

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Updates the list of contributors in README
file_pattern: README.md
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Updates the list of contributors in README
file_pattern: README.md
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn run lint-staged
1 change: 0 additions & 1 deletion .linelint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ ignore:
- examples/dotnet
- .github/markdown-images


rules:
# checks if file ends in a newline character
end-of-file:
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
webapp/public
third_party
*.md
monitoring/gen/*
.prettierignore
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "single-quote": true }
{ "singleQuote": true }
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ WORKDIR /opt/pyroscope

COPY scripts ./scripts
COPY webapp ./webapp
COPY package.json yarn.lock babel.config.js .eslintrc .eslintignore Makefile ./
COPY package.json yarn.lock babel.config.js .eslintrc .eslintignore .prettierrc Makefile ./

ARG EXTRA_METADATA=""
RUN EXTRA_METADATA=$EXTRA_METADATA make assets-release
Expand Down
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ["@babel/preset-env", "@babel/preset-react"],
plugins: ["transform-class-properties"],
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: ['transform-class-properties'],
};
10 changes: 4 additions & 6 deletions benchmark/ci/pr/dangerfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {markdown } from "danger"
import { markdown } from 'danger';
const fs = require('fs');
const path = require('path');


const metaReport = fs.readFileSync(path.join(__dirname,"./meta-report"));
const tableReport = fs.readFileSync(path.join(__dirname,"./table-report"));
const imgReport = fs.readFileSync(path.join(__dirname,"./image-report"));
const metaReport = fs.readFileSync(path.join(__dirname, './meta-report'));
const tableReport = fs.readFileSync(path.join(__dirname, './table-report'));
const imgReport = fs.readFileSync(path.join(__dirname, './image-report'));

// the markdown calls seem to be LIFO
// so it's easier to just use a single call
markdown(`${metaReport} \n${tableReport} \n${imgReport}`);

12 changes: 6 additions & 6 deletions benchmark/ci/pr/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
x-PYROSCOPE_CPUS: &PYROSCOPE_CPUS 1
x-PYROSCOPE_MEMORY: &PYROSCOPE_MEMORY 4096MB

version: "3.9"
version: '3.9'
services:
client:
build:
context: ../../../
dockerfile: benchmark/Dockerfile
# we will be running docker exec against it
command:
- sh
- -c
- sleep Infinity
- sh
- -c
- sleep Infinity
volumes:
- ./dashboard-screenshots:/screenshots
- ./report.yaml:/report.yaml
- ./dashboard-screenshots:/screenshots
- ./report.yaml:/report.yaml
pyroscope:
environment:
- PYROSCOPE_LOG_LEVEL=info
Expand Down
4 changes: 2 additions & 2 deletions benchmark/ci/pr/report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ baseName: main
targetName: pr

queries:
- name: "throughput"
- name: 'throughput'
base: 'rate(pyroscope_http_request_duration_seconds_count{handler="/ingest", instance="pyroscope:4040"}[5m])'
target: 'rate(pyroscope_http_request_duration_seconds_count{handler="/ingest", instance="pyroscope_main:4040"}[5m])'
diffThresholdPercent: 5
biggerIsBetter: true

- base: 'pyroscope_http_request_duration_seconds_count{handler="/ingest", instance="pyroscope:4040"}'
target: 'pyroscope_http_request_duration_seconds_count{handler="/ingest", instance="pyroscope_main:4040"}'
name: "total items processed"
name: 'total items processed'
diffThresholdPercent: 5
biggerIsBetter: true
17 changes: 8 additions & 9 deletions benchmark/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
version: "3.9"
version: '3.9'
services:
pyrobench:
env_file:
- run-parameters.env
- run-parameters.env
build:
context: ../
dockerfile: benchmark/Dockerfile
# we will be running docker exec against it
command:
- sh
- -c
- sleep Infinity
- sh
- -c
- sleep Infinity
volumes:
- ./dashboard-screenshots:/screenshots
- ./dashboard-screenshots:/screenshots

pyroscope:
environment:
Expand All @@ -28,8 +28,8 @@ services:
deploy:
resources:
limits:
cpus: "${PYROSCOPE_CPUS}"
memory: "${PYROSCOPE_MEMORY}"
cpus: '${PYROSCOPE_CPUS}'
memory: '${PYROSCOPE_MEMORY}'

prometheus:
image: prom/prometheus:v2.27.1
Expand All @@ -53,4 +53,3 @@ services:
volumes:
data-prometheus:
driver: local

20 changes: 3 additions & 17 deletions benchmark/grafana-provisioning/dashboards/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,7 @@
"links": [],
"options": {
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
Expand Down Expand Up @@ -1639,9 +1637,7 @@
"displayMode": "gradient",
"orientation": "vertical",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
Expand Down Expand Up @@ -1816,17 +1812,7 @@
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
"time_options": ["5m", "15m", "1h", "6h", "12h", "24h", "2d", "7d", "30d"]
},
"timezone": "browser",
"title": "main",
Expand Down
10 changes: 5 additions & 5 deletions benchmark/grafana-provisioning/dashboards/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: 1

providers:
- name: dashboards
type: file
updateIntervalSeconds: 5
options:
path: /etc/grafana/provisioning/dashboards
- name: dashboards
type: file
updateIntervalSeconds: 5
options:
path: /etc/grafana/provisioning/dashboards
18 changes: 9 additions & 9 deletions benchmark/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# my global config
global:
scrape_interval: 1s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
scrape_interval: 1s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
- static_configs:
- targets:
# - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
Expand All @@ -26,8 +26,8 @@ scrape_configs:
# scheme defaults to 'http'.

static_configs:
- targets:
- 'localhost:9090'
- 'pyroscope:4040'
- 'pyroscope_main:4040'
- 'pushgateway:9091'
- targets:
- 'localhost:9090'
- 'pyroscope:4040'
- 'pyroscope_main:4040'
- 'pushgateway:9091'
15 changes: 8 additions & 7 deletions benchmark/take-screenshot.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
console.log("puppeteer start");
console.log('puppeteer start');

const puppeteer = require("puppeteer");
const puppeteer = require('puppeteer');

function timeout(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
Expand All @@ -9,15 +9,16 @@ function timeout(ms) {
const args = process.argv.slice(2);

const from = args[1];
console.log('from', from)

(async () => {
console.log(
'from',
from
)(async () => {
const browser = await puppeteer.launch({});
const page = await browser.newPage();
await page.setViewport({ width: 1600, height: 1280 });
await page.goto(
`http://localhost:8080/d/65gjqY3Mk/main?orgId=1&from=${from}`,
{ waitUntil: "networkidle2" }
{ waitUntil: 'networkidle2' }
);
await timeout(2000);
await page.screenshot({
Expand All @@ -27,4 +28,4 @@ console.log('from', from)
browser.close();
})();

console.log("puppeteer stop");
console.log('puppeteer stop');
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ignore:
- "**/*.pb.go" # auto-generated code
- '**/*.pb.go' # auto-generated code
Loading

0 comments on commit fffac60

Please sign in to comment.