Merge branch 'feature/cleanup-codemirror' into feature/use-npm-workspace

This commit is contained in:
Augustin Husson 2021-09-09 17:55:50 +02:00
commit fa56d1e43b
39 changed files with 24 additions and 11229 deletions

View file

@ -137,6 +137,7 @@ func main() {
analyzePath := tsdbAnalyzeCmd.Arg("db path", "Database path (default is "+defaultDBPath+").").Default(defaultDBPath).String()
analyzeBlockID := tsdbAnalyzeCmd.Arg("block id", "Block to analyze (default is the last block).").String()
analyzeLimit := tsdbAnalyzeCmd.Flag("limit", "How many items to show in each list.").Default("20").Int()
analyzeRunExtended := tsdbAnalyzeCmd.Flag("extended", "Run extended analysis.").Bool()
tsdbListCmd := tsdbCmd.Command("list", "List tsdb blocks.")
listHumanReadable := tsdbListCmd.Flag("human-readable", "Print human readable values.").Short('r').Bool()
@ -237,7 +238,7 @@ func main() {
os.Exit(checkErr(benchmarkWrite(*benchWriteOutPath, *benchSamplesFile, *benchWriteNumMetrics, *benchWriteNumScrapes)))
case tsdbAnalyzeCmd.FullCommand():
os.Exit(checkErr(analyzeBlock(*analyzePath, *analyzeBlockID, *analyzeLimit)))
os.Exit(checkErr(analyzeBlock(*analyzePath, *analyzeBlockID, *analyzeLimit, *analyzeRunExtended)))
case tsdbListCmd.FullCommand():
os.Exit(checkErr(listBlocks(*listPath, *listHumanReadable)))

View file

@ -418,7 +418,7 @@ func openBlock(path, blockID string) (*tsdb.DBReadOnly, tsdb.BlockReader, error)
return db, block, nil
}
func analyzeBlock(path, blockID string, limit int) error {
func analyzeBlock(path, blockID string, limit int, runExtended bool) error {
db, block, err := openBlock(path, blockID)
if err != nil {
return err
@ -564,9 +564,13 @@ func analyzeBlock(path, blockID string, limit int) error {
fmt.Printf("\nHighest cardinality metric names:\n")
printInfo(postingInfos)
if runExtended {
return analyzeCompaction(block, ir)
}
return nil
}
func analyzeCompaction(block tsdb.BlockReader, indexr tsdb.IndexReader) (err error) {
postingsr, err := indexr.Postings(index.AllPostingsKey())
if err != nil {

View file

@ -4,8 +4,8 @@ node_modules/
dist/
lib/
src/lang-promql/grammar/**.ts
src/lang-promql/grammar/parser.js
src/lang-promql/grammar/parser.terms.js
src/grammar/**.ts
src/grammar/parser.js
src/grammar/parser.terms.js
/.nyc_output

File diff suppressed because it is too large Load diff

View file

@ -5,12 +5,10 @@
"main": "cjs/index.js",
"module": "esm/index.js",
"scripts": {
"start": "webpack-dev-server --config webpack.config.cjs --open",
"build": "npm run build:grammar && npm run build:lib && npm run build:app",
"build:grammar": "lezer-generator src/lang-promql/grammar/promql.grammar -o src/lang-promql/grammar/parser",
"build": "npm run build:grammar && npm run build:lib",
"build:grammar": "lezer-generator src/grammar/promql.grammar -o src/grammar/parser",
"build:lib": "bash ./build.sh",
"build:app": "webpack --config webpack.config.cjs",
"test": "npm run build:grammar && ts-mocha -p tsconfig.json src/**/*.test.ts",
"test": "npm run build:grammar && ts-mocha -p tsconfig.json ./**/*.test.ts",
"test-coverage": "npm run build:grammar && nyc ts-mocha -p ./tsconfig.json ./**/*.test.ts",
"codecov": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"lint": "eslint src/ --ext .ts",
@ -68,10 +66,7 @@
"ts-loader": "^7.0.4",
"ts-mocha": "^8.0.0",
"ts-node": "^9.0.0",
"typescript": "^4.2.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0"
"typescript": "^4.2.3"
},
"peerDependencies": {
"@codemirror/autocomplete": "^0.18.3",

View file

@ -1,48 +0,0 @@
<!-- The MIT License (MIT)
Copyright (c) 2020 The Prometheus Authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PromQL</title>
</head>
<body>
<h3>CodeMirror Mode PromQL</h3>
<label for="completion">choose the completion mode:</label>
<select name="completion" id="completion">
<option selected value="offline">Offline</option>
<option value="prometheus">Prometheus</option>
</select>
<br>
<label for="languageType">Language to complete</label>
<select name="languageType" id="languageType">
<option selected value="promql">Full PromQL</option>
<option value="metricName">Metric names</option>
</select>
<button id="apply">apply</button>
<div id=editor></div>
</body>
</html>

View file

@ -1,85 +0,0 @@
// Copyright 2021 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { basicSetup } from '@codemirror/basic-setup';
import { EditorState } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import { LanguageType, PromQLExtension } from '../lang-promql';
import { customTheme, promQLHighlightMaterialTheme } from './theme';
const promqlExtension = new PromQLExtension();
let editor: EditorView;
function getLanguageType(): LanguageType {
const completionSelect = document.getElementById('languageType') as HTMLSelectElement;
const completionValue = completionSelect.options[completionSelect.selectedIndex].value;
switch (completionValue) {
case 'promql':
return LanguageType.PromQL;
case 'metricName':
return LanguageType.MetricName;
default:
return LanguageType.PromQL;
}
}
function setCompletion() {
const completionSelect = document.getElementById('completion') as HTMLSelectElement;
const completionValue = completionSelect.options[completionSelect.selectedIndex].value;
switch (completionValue) {
case 'offline':
promqlExtension.setComplete();
break;
case 'prometheus':
promqlExtension.setComplete({
remote: {
url: 'https://prometheus.demo.do.prometheus.io',
},
});
break;
default:
promqlExtension.setComplete();
}
}
function createEditor() {
let doc = '';
if (editor) {
// When the linter is changed, it required to reload completely the editor.
// So the first thing to do, is to completely delete the previous editor and to recreate it from scratch
// We should preserve the current text entered as well.
doc = editor.state.sliceDoc(0, editor.state.doc.length);
editor.destroy();
}
editor = new EditorView({
state: EditorState.create({
extensions: [basicSetup, promqlExtension.asExtension(getLanguageType()), promQLHighlightMaterialTheme, customTheme],
doc: doc,
}),
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
parent: document.querySelector('#editor')!,
});
}
function applyConfiguration(): void {
setCompletion();
createEditor();
}
createEditor();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion,@typescript-eslint/ban-ts-ignore
// @ts-ignore
document.getElementById('apply').addEventListener('click', function () {
applyConfiguration();
});

View file

@ -1,105 +0,0 @@
// Copyright 2021 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { EditorView } from '@codemirror/view';
import { HighlightStyle, tags } from '@codemirror/highlight';
// promQLHighlightMaterialTheme is based on the material theme defined here:
// https://codemirror.net/theme/material.css
export const promQLHighlightMaterialTheme = HighlightStyle.define([
{
tag: tags.deleted,
textDecoration: 'line-through',
},
{
tag: tags.inserted,
textDecoration: 'underline',
},
{
tag: tags.link,
textDecoration: 'underline',
},
{
tag: tags.strong,
fontWeight: 'bold',
},
{
tag: tags.emphasis,
fontStyle: 'italic',
},
{
tag: tags.invalid,
color: '#f00',
},
{
tag: tags.keyword,
color: '#C792EA',
},
{
tag: tags.operator,
color: '#89DDFF',
},
{
tag: tags.atom,
color: '#F78C6C',
},
{
tag: tags.number,
color: '#FF5370',
},
{
tag: tags.string,
color: '#99b867',
},
{
tag: [tags.escape, tags.regexp],
color: '#e40',
},
{
tag: tags.definition(tags.variableName),
color: '#f07178',
},
{
tag: tags.labelName,
color: '#f07178',
},
{
tag: tags.typeName,
color: '#085',
},
{
tag: tags.function(tags.variableName),
color: '#C792EA',
},
{
tag: tags.definition(tags.propertyName),
color: '#00c',
},
{
tag: tags.comment,
color: '#546E7A',
},
]);
export const customTheme = EditorView.theme({
$completionDetail: {
marginLeft: '0.5em',
float: 'right',
color: '#9d4040',
},
$completionMatchedText: {
color: '#83080a',
textDecoration: 'none',
fontWeight: 'bold',
},
});

View file

@ -13,7 +13,7 @@
import chai from 'chai';
import { analyzeCompletion, computeStartCompletePosition, ContextKind } from './hybrid';
import { createEditorState, mockedMetricsTerms, mockPrometheusServer } from '../../test/utils';
import { createEditorState, mockedMetricsTerms, mockPrometheusServer } from '../test/utils.test';
import { Completion, CompletionContext } from '@codemirror/autocomplete';
import {
aggregateOpModifierTerms,

View file

@ -4,7 +4,7 @@ import { fileTests } from 'lezer-generator/dist/test';
import * as fs from 'fs';
import * as path from 'path';
const caseDir = './src/lang-promql/grammar/test';
const caseDir = './src/grammar/test';
for (const file of fs.readdirSync(caseDir)) {
if (!/\.txt$/.test(file)) continue;

View file

@ -14,7 +14,7 @@
import chai from 'chai';
import { Parser } from './parser';
import { Diagnostic } from '@codemirror/lint';
import { createEditorState } from '../../test/utils';
import { createEditorState } from '../test/utils.test';
import { syntaxTree } from '@codemirror/language';
import { ValueType } from '../types';

View file

@ -33,7 +33,7 @@ import {
Sub,
VectorSelector,
} from '../grammar/parser.terms';
import { createEditorState } from '../../test/utils';
import { createEditorState } from '../test/utils.test';
import { containsAtLeastOneChild, containsChild, retrieveAllRecursiveNodes, walkBackward, walkThrough } from './path-finder';
import { SyntaxNode } from 'lezer-tree';
import { syntaxTree } from '@codemirror/language';

View file

@ -12,7 +12,7 @@
// limitations under the License.
import { buildVectorMatching } from './vector';
import { createEditorState } from '../../test/utils';
import { createEditorState } from '../test/utils.test';
import { walkThrough } from './path-finder';
import { BinaryExpr, Expr } from '../grammar/parser.terms';
import chai from 'chai';

View file

@ -11,7 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { parser } from '../lang-promql/grammar/parser';
import { parser } from '../grammar/parser';
import { EditorState } from '@codemirror/state';
import { LezerLanguage } from '@codemirror/language';
import nock from 'nock';

View file

@ -17,7 +17,7 @@
"allowJs": true
},
"include": [
"src/lang-promql"
"src/"
],
"exclude": [
"node_modules",

View file

@ -1,40 +0,0 @@
// eslint-disable-next-line @typescript-eslint/no-var-requires
const path = require('path');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const HtmlWebpackPlugin = require('html-webpack-plugin');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
module.exports = {
mode: 'development',
entry: path.join(__dirname, '/src/app/app.ts'),
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
],
},
plugins: [
new CleanWebpackPlugin({ cleanStaleWebpackAssets: false }),
new HtmlWebpackPlugin({
hash: true,
filename: 'index.html', //relative to root of the application
path: path.resolve(__dirname, 'dist'),
template: './src/app/app.html',
}),
],
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
devServer: {
contentBase: './dist',
},
};