Skip to content

Commit

Permalink
chore: support more function, bypassed some
Browse files Browse the repository at this point in the history
Signed-off-by: clavinjune <[email protected]>
  • Loading branch information
clavinjune committed Oct 10, 2023
1 parent f88bdac commit 0738ea4
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
4 changes: 2 additions & 2 deletions web/ui/module/codemirror-metricsql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clavinjune/codemirror-metricsql",
"version": "0.0.1-dev.0910230001",
"version": "0.0.1-dev.1010230001",
"description": "a CodeMirror mode for the MetricsQL language",
"types": "dist/esm/index.d.ts",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -31,7 +31,7 @@
},
"homepage": "https://github.com/clavinjune/prometheus-codemirror-metricsql/blob/main/web/ui/module/codemirror-metricsql/README.md",
"dependencies": {
"@clavinjune/lezer-metricsql": "0.0.1-dev.2909230003",
"@clavinjune/lezer-metricsql": "0.0.1-dev.1010230001",
"lru-cache": "^7.18.3"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions web/ui/module/codemirror-metricsql/src/parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,12 @@ describe('promql operations', () => {
expectedValueType: ValueType.vector,
expectedDiag: [],
},
// custom transform function
{
expr: 'avg_daily(3, sum(increase(istio_requests_total{job="envoy-stats", app="gopaysh-istio-internal-gateway", cluster_name="goku-eks-production-01"}[10m])))',
expectedValueType: ValueType.vector,
expectedDiag: [],
},
// bypassed until supported
{
expr: 'histogram_quantiles("le", 0.3, 0.5, sum(rate(http_request_duration_seconds_bucket[5m]) by (le))',
Expand Down
36 changes: 36 additions & 0 deletions web/ui/module/codemirror-metricsql/src/types/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ import {
Vector,
Year,
ZscoreOverTime,
AvgDaily,
MedianDaily,
AvgWeekly,
MedianWeekly,
MedianWeeklyWithTrends,
} from '@clavinjune/lezer-metricsql';

export enum ValueType {
Expand Down Expand Up @@ -862,6 +867,37 @@ const promqlFunctions: { [key: number]: PromQLFunction } = {
variadic: 1,
returnType: ValueType.vector,
},
// custom transform function
[AvgDaily]: {
name: 'avg_daily',
argTypes: [ValueType.scalar, ValueType.vector],
variadic: 0,
returnType: ValueType.vector,
},
[MedianDaily]: {
name: 'median_daily',
argTypes: [ValueType.scalar, ValueType.vector],
variadic: 0,
returnType: ValueType.vector,
},
[AvgWeekly]: {
name: 'avg_weekly',
argTypes: [ValueType.scalar, ValueType.vector],
variadic: 0,
returnType: ValueType.vector,
},
[MedianWeekly]: {
name: 'median_weekly',
argTypes: [ValueType.scalar, ValueType.vector],
variadic: 0,
returnType: ValueType.vector,
},
[MedianWeeklyWithTrends]: {
name: 'median_weekly_with_trends',
argTypes: [ValueType.scalar, ValueType.vector],
variadic: 0,
returnType: ValueType.vector,
},
};

export function getFunction(id: number): PromQLFunction {
Expand Down
2 changes: 1 addition & 1 deletion web/ui/module/lezer-metricsql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clavinjune/lezer-metricsql",
"version": "0.0.1-dev.2909230003",
"version": "0.0.1-dev.1010230001",
"description": "lezer-based MetricsQL grammar",
"main": "dist/index.cjs",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion web/ui/module/lezer-metricsql/src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const promQLHighLight = styleTags({
NumberLiteral: tags.number,
Duration: tags.number,
Identifier: tags.variableName,
'Abs Absent AbsentOverTime Acos Acosh Asin Asinh Atan Atanh AvgOverTime Ceil Changes Clamp ClampMax ClampMin Cos Cosh CountOverTime DaysInMonth DayOfMonth DayOfWeek DayOfYear Deg Delta Deriv Exp Floor HistogramCount HistogramFraction HistogramQuantile HistogramSum HoltWinters Hour Idelta Increase Irate LabelReplace LabelJoin LastOverTime Ln Log10 Log2 MaxOverTime MinOverTime Minute Month Pi PredictLinear PresentOverTime QuantileOverTime Rad Rate Resets Round Scalar Sgn Sin Sinh Sort SortDesc Sqrt StddevOverTime StdvarOverTime SumOverTime Tan Tanh Time Timestamp Vector Year AggrOverTime AscentOverTime BitmapAnd BitmapOr BitmapXor BucketsLimit ChangesPrometheus CountEqOverTime CountGtOverTime CountLeOverTime CountNeOverTime DecreasesOverTime DefaultRollup DeltaPrometheus DerivFast DescentOverTime DistinctOverTime DropCommonLabels DurationOverTime FirstOverTime GeomeanOverTime HistogramAvg HistogramOverTime HistogramQuantiles HistogramShare HoeffdingBoundLower HoeffdingBoundUpper Ideriv IncreasePrometheus IncreasePure IncreasesOverTime Integrate Interpolate KeepLastValue KeepNextValue LabelCopy LabelDel LabelGraphiteGroup LabelKeep LabelLowercase LabelMap LabelMatch LabelMismatch LabelMove LabelSet LabelTransform LabelUppercase LabelValue Lag Lifetime LimitOffset MadOverTime MedianOverTime ModeOverTime Now PrometheusBuckets QuantilesOverTime Rand RandExponential RandNormal RangeAvg RangeFirst RangeLast RangeLinearRegression RangeMad RangeMax RangeMin RangeNormalize RangeOverTime RangeQuantile RangeStddev RangeStdvar RangeSum RangeTrimOutliers RangeTrimSpikes RangeTrimZscore RangeZscore RateOverSum RemoveResets Rollup RollupCandlestick RollupDelta RollupDeriv RollupIncrease RollupRate RollupScrapeInterval RunningAvg RunningMax RunningMin RunningSum ScrapeInterval ShareEqOverTime ShareGtOverTime ShareLeOverTime SmoothExponential SortByLabel SortByLabelDesc SortByLabelNumeric SortByLabelNumericDesc StaleSamplesOverTime Step Sum2OverTime TfirstOverTime TimestampWithName TimezoneOffset TlastChangeOverTime TlastOverTime TmaxOverTime TminOverTime Union ZscoreOverTime': tags.function(tags.variableName),
'Abs Absent AbsentOverTime Acos Acosh Asin Asinh Atan Atanh AvgOverTime Ceil Changes Clamp ClampMax ClampMin Cos Cosh CountOverTime DaysInMonth DayOfMonth DayOfWeek DayOfYear Deg Delta Deriv Exp Floor HistogramCount HistogramFraction HistogramQuantile HistogramSum HoltWinters Hour Idelta Increase Irate LabelReplace LabelJoin LastOverTime Ln Log10 Log2 MaxOverTime MinOverTime Minute Month Pi PredictLinear PresentOverTime QuantileOverTime Rad Rate Resets Round Scalar Sgn Sin Sinh Sort SortDesc Sqrt StddevOverTime StdvarOverTime SumOverTime Tan Tanh Time Timestamp Vector Year AggrOverTime AscentOverTime BitmapAnd BitmapOr BitmapXor BucketsLimit ChangesPrometheus CountEqOverTime CountGtOverTime CountLeOverTime CountNeOverTime DecreasesOverTime DefaultRollup DeltaPrometheus DerivFast DescentOverTime DistinctOverTime DropCommonLabels DurationOverTime FirstOverTime GeomeanOverTime HistogramAvg HistogramOverTime HistogramQuantiles HistogramShare HoeffdingBoundLower HoeffdingBoundUpper Ideriv IncreasePrometheus IncreasePure IncreasesOverTime Integrate Interpolate KeepLastValue KeepNextValue LabelCopy LabelDel LabelGraphiteGroup LabelKeep LabelLowercase LabelMap LabelMatch LabelMismatch LabelMove LabelSet LabelTransform LabelUppercase LabelValue Lag Lifetime LimitOffset MadOverTime MedianOverTime ModeOverTime Now PrometheusBuckets QuantilesOverTime Rand RandExponential RandNormal RangeAvg RangeFirst RangeLast RangeLinearRegression RangeMad RangeMax RangeMin RangeNormalize RangeOverTime RangeQuantile RangeStddev RangeStdvar RangeSum RangeTrimOutliers RangeTrimSpikes RangeTrimZscore RangeZscore RateOverSum RemoveResets Rollup RollupCandlestick RollupDelta RollupDeriv RollupIncrease RollupRate RollupScrapeInterval RunningAvg RunningMax RunningMin RunningSum ScrapeInterval ShareEqOverTime ShareGtOverTime ShareLeOverTime SmoothExponential SortByLabel SortByLabelDesc SortByLabelNumeric SortByLabelNumericDesc StaleSamplesOverTime Step Sum2OverTime TfirstOverTime TimestampWithName TimezoneOffset TlastChangeOverTime TlastOverTime TmaxOverTime TminOverTime Union ZscoreOverTime AvgDaily MedianDaily AvgWeekly MedianWeekly MedianWeeklyWithTrends': tags.function(tags.variableName),
'Any Avg Bottomk Count Count_values Group Max Min Quantile Stddev Stdvar Sum Topk Any BottomkAvg BottomkLast BottomkMax BottomkMedian BottomkMin Distinct Geomean Histogram Limitk Mad Median Mode OutliersMad Outliersk Quantiles Share Sum2 TopkAvg TopkLast TopkMax TopkMedian TopkMin Zscore': tags.operatorKeyword,
'By Without Bool On Ignoring GroupLeft GroupRight Offset Start End': tags.modifier,
'And Unless Or': tags.logicOperator,
Expand Down
14 changes: 13 additions & 1 deletion web/ui/module/lezer-metricsql/src/promql.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ FunctionIdentifier {
TmaxOverTime |
TminOverTime |
Union |
ZscoreOverTime
ZscoreOverTime |
// custom transform function
AvgDaily |
MedianDaily |
AvgWeekly |
MedianWeekly |
MedianWeeklyWithTrends
}

FunctionCallBody {
Expand Down Expand Up @@ -682,6 +688,12 @@ NumberLiteral {
TminOverTime { condFn<"tmin_over_time"> }
Union { condFn<"union"> }
ZscoreOverTime { condFn<"zscore_over_time"> }
// custom transform function
AvgDaily { condFn<"avg_daily"> }
MedianDaily { condFn<"median_daily"> }
AvgWeekly { condFn<"avg_weekly"> }
MedianWeekly { condFn<"median_weekly"> }
MedianWeeklyWithTrends { condFn<"median_weekly_with_trends"> }

// Conditional function names (only parsed as function names when used as such).
condFn<term> { @extend<Identifier, term> }

0 comments on commit 0738ea4

Please sign in to comment.