diff --git a/.github/workflows/publish-nuget-packages.yaml b/.github/workflows/publish-nuget-packages.yaml index 48e2b30..f3b49bc 100644 --- a/.github/workflows/publish-nuget-packages.yaml +++ b/.github/workflows/publish-nuget-packages.yaml @@ -8,10 +8,10 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: actions/setup-dotnet@v1 + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 with: - dotnet-version: '6.0.x' + dotnet-version: '8.0.x' - run: | echo "Github ref is ${GITHUB_REF}" arrTag=(${GITHUB_REF//\// }) diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 9b10467..e2185a0 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -9,13 +9,13 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Setup .NET Core 3.1 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 3.1.x - name: Setup .NET Core 6.0 - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: '6.0.x' - - uses: actions/checkout@v1 + - name: Setup .NET Core 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.0.x' + - uses: actions/checkout@v4 - run: dotnet test -c "Debug" \ No newline at end of file diff --git a/src/PromQL.Parser/Functions.cs b/src/PromQL.Parser/Functions.cs index de8c0d1..eb10934 100644 --- a/src/PromQL.Parser/Functions.cs +++ b/src/PromQL.Parser/Functions.cs @@ -9,7 +9,7 @@ public static class Functions /// /// /// Primarily taken from https://github.com/prometheus/prometheus/blob/main/web/ui/module/codemirror-promql/src/grammar/promql.grammar#L121-L188. - /// More authoritative source would be https://github.com/prometheus/prometheus/blob/7471208b5c8ff6b65b644adedf7eb964da3d50ae/promql/parser/functions.go. + /// More authoritative source would be https://github.com/prometheus/prometheus/blob/38fd48e6b54b5413b5281efbeeb989a44845be34/promql/parser/functions.go. /// public static ImmutableDictionary Map { get; set; } = new[] { @@ -34,15 +34,23 @@ public static class Functions new Function("days_in_month", ValueType.Vector, varadicModifier: 1 , ValueType.Vector), new Function("day_of_month", ValueType.Vector, varadicModifier: 1, ValueType.Vector), new Function("day_of_week", ValueType.Vector, varadicModifier: 1, ValueType.Vector), + new Function("day_of_year", ValueType.Vector, varadicModifier: 1, ValueType.Vector), new Function("deg", ValueType.Vector, ValueType.Vector), new Function("delta", ValueType.Vector, ValueType.Matrix), new Function("deriv", ValueType.Vector, ValueType.Matrix), new Function("exp", ValueType.Vector, ValueType.Vector), new Function("floor", ValueType.Vector, ValueType.Vector), + new Function("histogram_avg", ValueType.Vector, ValueType.Vector), + new Function("histogram_count", ValueType.Vector, ValueType.Vector), + new Function("histogram_sum", ValueType.Vector, ValueType.Vector), + new Function("histogram_stddev", ValueType.Vector, ValueType.Vector), + new Function("histogram_stdvar", ValueType.Vector, ValueType.Vector), + new Function("histogram_fraction", ValueType.Vector, ValueType.Scalar, ValueType.Scalar, ValueType.Vector), new Function("histogram_quantile", ValueType.Vector, ValueType.Scalar, ValueType.Vector), - new Function("holt_winters", ValueType.Vector, ValueType.Matrix, ValueType.Scalar, ValueType.Scalar), + new Function("double_exponential_smoothing", ValueType.Vector, ValueType.Matrix, ValueType.Scalar, ValueType.Scalar), new Function("hour", ValueType.Vector, varadicModifier: 1, ValueType.Vector), new Function("idelta", ValueType.Vector, ValueType.Matrix), + new Function("info", ValueType.Vector, varadicModifier: 1, ValueType.Vector, ValueType.Vector), new Function("increase", ValueType.Vector, ValueType.Matrix), new Function("irate", ValueType.Vector, ValueType.Matrix), new Function("label_replace", ValueType.Vector, ValueType.Vector, ValueType.String, ValueType.String, ValueType.String, ValueType.String), @@ -51,6 +59,7 @@ public static class Functions new Function("ln", ValueType.Vector, ValueType.Vector), new Function("log_10", ValueType.Vector, ValueType.Vector), new Function("log_2", ValueType.Vector, ValueType.Vector), + new Function("mad_over_time", ValueType.Vector, ValueType.Matrix), new Function("max_over_time", ValueType.Vector, ValueType.Matrix), new Function("min_over_time", ValueType.Vector, ValueType.Matrix), new Function("minute", ValueType.Vector, varadicModifier: 1, ValueType.Vector), @@ -69,6 +78,8 @@ public static class Functions new Function("sinh", ValueType.Vector, ValueType.Vector), new Function("sort", ValueType.Vector, ValueType.Vector), new Function("sort_desc", ValueType.Vector, ValueType.Vector), + new Function("sort_by_label", ValueType.Vector, varadicModifier: 0, ValueType.Vector, ValueType.String), + new Function("sort_by_label_desc", ValueType.Vector, varadicModifier: 0, ValueType.Vector, ValueType.String), new Function("sqrt", ValueType.Vector, ValueType.Vector), new Function("stddev_over_time", ValueType.Vector, ValueType.Matrix), new Function("stdvar_over_time", ValueType.Vector, ValueType.Matrix), diff --git a/src/PromQL.Parser/Operators.cs b/src/PromQL.Parser/Operators.cs index 8e6182d..7f9b546 100644 --- a/src/PromQL.Parser/Operators.cs +++ b/src/PromQL.Parser/Operators.cs @@ -137,7 +137,9 @@ public enum Unary new AggregateOperator("topk", ValueType.Scalar), new AggregateOperator("bottomk", ValueType.Scalar), new AggregateOperator("count_values", ValueType.String), - new AggregateOperator("quantile", ValueType.Scalar) + new AggregateOperator("quantile", ValueType.Scalar), + new AggregateOperator("limitk", ValueType.Scalar), + new AggregateOperator("limit_ratio", ValueType.Scalar) }.ToImmutableDictionary(k => k.Name, v => v, StringComparer.OrdinalIgnoreCase); public static string ToPromQl(this Operators.Binary op) => op switch diff --git a/src/PromQL.Parser/PromQL.Parser.csproj b/src/PromQL.Parser/PromQL.Parser.csproj index c1f7d75..d140b24 100644 --- a/src/PromQL.Parser/PromQL.Parser.csproj +++ b/src/PromQL.Parser/PromQL.Parser.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1;net6.0 + net6.0;net8.0 10 enable true diff --git a/tests/PromQL.Parser.Tests/ParserTests.cs b/tests/PromQL.Parser.Tests/ParserTests.cs index 59a5afa..831e4e7 100644 --- a/tests/PromQL.Parser.Tests/ParserTests.cs +++ b/tests/PromQL.Parser.Tests/ParserTests.cs @@ -383,11 +383,26 @@ public void FunctionCall_InvalidParameterCountVaradic() [TestCase("hour()")] [TestCase("hour(one)")] [TestCase("hour(one, two)")] - [TestCase("label_join(instant_vector, 'dst_label', 'separator', 'one', 'two')")] - public void FunctionCall_Varadic(string query) + public void FunctionCall_Varadic_One(string query) { Parse(Parser.Expr, query).Should().BeOfType(); } + + [Test] + public void FunctionCall_Varadic_Label_Join() + { + var exp = Parse(Parser.Expr, "label_join(instant_vector, 'dst_label', 'separator', 'one', 'two')").Should().BeOfType().Subject; + exp.Args.Should().HaveCount(5); + } + + [Test] + [TestCase("sort_by_label(my_metric, 'one', 'two', 'three')")] + [TestCase("sort_by_label_desc(my_metric, 'one', 'two', 'three')")] + public void FunctionCall_Varadic_Sort(string query) + { + var exp = Parse(Parser.Expr, query).Should().BeOfType().Subject; + exp.Args.Should().HaveCount(4); + } [Test] public void FunctionCall_OneArg() => Parse(Parser.Expr, "abs (1)") @@ -850,6 +865,8 @@ public void BinaryExpr_BoolNonComparison(string query) [TestCase("stdvar (blah)", "stdvar")] [TestCase("sum (blah)", "sum")] [TestCase("topk (1, blah)", "topk")] + [TestCase("limitk (1, blah)", "limitk")] + [TestCase("limit_ratio (1, blah)", "limit_ratio")] public void AggregateExpr_Operator(string input, string expected) => Parse(Parser.AggregateExpr, input) .Operator.Name.Should().Be(expected); diff --git a/tests/PromQL.Parser.Tests/PromQL.Parser.Tests.csproj b/tests/PromQL.Parser.Tests/PromQL.Parser.Tests.csproj index 7ade3d5..2c19004 100644 Binary files a/tests/PromQL.Parser.Tests/PromQL.Parser.Tests.csproj and b/tests/PromQL.Parser.Tests/PromQL.Parser.Tests.csproj differ