Skip to content

Commit

Permalink
Import CelMatcher and HttpAttributesCelMatchInput
Browse files Browse the repository at this point in the history
http_inputs.proto provides HttpAttributesCelMatchInput, which can be
used as a typed config in `bucket_matchers` predicate input.
  • Loading branch information
sergiitk committed Jul 31, 2024
1 parent 99a64bd commit 54924e0
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xds/third_party/xds/import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ xds/core/v3/resource_locator.proto
xds/core/v3/resource_name.proto
xds/data/orca/v3/orca_load_report.proto
xds/service/orca/v3/orca.proto
xds/type/matcher/v3/cel.proto
xds/type/matcher/v3/matcher.proto
xds/type/matcher/v3/regex.proto
xds/type/matcher/v3/string.proto
xds/type/v3/cel.proto
xds/type/matcher/v3/http_inputs.proto
xds/type/v3/typed_struct.proto
)

Expand Down
42 changes: 42 additions & 0 deletions xds/third_party/xds/src/main/proto/xds/type/matcher/v3/cel.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
syntax = "proto3";

package xds.type.matcher.v3;

import "xds/annotations/v3/status.proto";
import "xds/type/v3/cel.proto";

import "validate/validate.proto";

option java_package = "com.github.xds.type.matcher.v3";
option java_outer_classname = "CelProto";
option java_multiple_files = true;
option go_package = "github.com/cncf/xds/go/xds/type/matcher/v3";

option (xds.annotations.v3.file_status).work_in_progress = true;

// [#protodoc-title: Common Expression Language (CEL) matchers]

// Performs a match by evaluating a `Common Expression Language
// <https://github.com/google/cel-spec>`_ (CEL) expression against the standardized set of
// :ref:`HTTP attributes <arch_overview_attributes>` specified via ``HttpAttributesCelMatchInput``.
//
// .. attention::
//
// The match is ``true``, iff the result of the evaluation is a bool AND true.
// In all other cases, the match is ``false``, including but not limited to: non-bool types,
// ``false``, ``null``,`` int(1)``, etc.
// In case CEL expression raises an error, the result of the evaluation is interpreted "no match".
//
// Refer to :ref:`Unified Matcher API <envoy_v3_api_msg_.xds.type.matcher.v3.Matcher>` documentation
// for usage details.
//
// [#comment:TODO(sergiitk): Link HttpAttributesMatchInput + usage example.]
// [#comment:TODO(sergiitk): When implemented, add the extension tag.]
message CelMatcher {
// Either parsed or checked representation of the CEL program.
type.v3.CelExpression expr_match = 1 [(validate.rules).message = {required: true}];

// Free-form description of the CEL AST, e.g. the original expression text, to be
// used for debugging assistance.
string description = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

package xds.type.matcher.v3;

import "xds/annotations/v3/status.proto";

option java_package = "com.github.xds.type.matcher.v3";
option java_outer_classname = "HttpInputsProto";
option java_multiple_files = true;
option go_package = "github.com/cncf/xds/go/xds/type/matcher/v3";

option (xds.annotations.v3.file_status).work_in_progress = true;

// [#protodoc-title: Common HTTP Inputs]

// Specifies that matching should be performed on the set of :ref:`HTTP attributes
// <arch_overview_attributes>`.
//
// The attributes will be exposed via `Common Expression Language
// <https://github.com/google/cel-spec>`_ runtime to associated CEL matcher.
//
// Refer to :ref:`Unified Matcher API <envoy_v3_api_msg_.xds.type.matcher.v3.Matcher>` documentation
// for usage details.
//
// [#comment:TODO(sergiitk): When implemented, add the extension tag.]
message HttpAttributesCelMatchInput {
}
70 changes: 70 additions & 0 deletions xds/third_party/xds/src/main/proto/xds/type/v3/cel.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
syntax = "proto3";

package xds.type.v3;

import "google/api/expr/v1alpha1/checked.proto";
import "google/api/expr/v1alpha1/syntax.proto";
import "cel/expr/checked.proto";
import "cel/expr/syntax.proto";
import "google/protobuf/wrappers.proto";

import "xds/annotations/v3/status.proto";

import "validate/validate.proto";

option java_package = "com.github.xds.type.v3";
option java_outer_classname = "CelProto";
option java_multiple_files = true;
option go_package = "github.com/cncf/xds/go/xds/type/v3";

option (xds.annotations.v3.file_status).work_in_progress = true;

// [#protodoc-title: Common Expression Language (CEL)]

// Either parsed or checked representation of the `Common Expression Language
// <https://github.com/google/cel-spec>`_ (CEL) program.
message CelExpression {
oneof expr_specifier {
// Parsed expression in abstract syntax tree (AST) form.
//
// Deprecated -- use ``cel_expr_parsed`` field instead.
// If ``cel_expr_parsed`` or ``cel_expr_checked`` is set, this field is not used.
google.api.expr.v1alpha1.ParsedExpr parsed_expr = 1 [deprecated = true];

// Parsed expression in abstract syntax tree (AST) form that has been successfully type checked.
//
// Deprecated -- use ``cel_expr_checked`` field instead.
// If ``cel_expr_parsed`` or ``cel_expr_checked`` is set, this field is not used.
google.api.expr.v1alpha1.CheckedExpr checked_expr = 2 [deprecated = true];
}

// Parsed expression in abstract syntax tree (AST) form.
//
// If ``cel_expr_checked`` is set, this field is not used.
cel.expr.ParsedExpr cel_expr_parsed = 3;

// Parsed expression in abstract syntax tree (AST) form that has been successfully type checked.
//
// If set, takes precedence over ``cel_expr_parsed``.
cel.expr.CheckedExpr cel_expr_checked = 4;
}

// Extracts a string by evaluating a `Common Expression Language
// <https://github.com/google/cel-spec>`_ (CEL) expression against the standardized set of
// :ref:`HTTP attributes <arch_overview_attributes>`.
//
// .. attention::
//
// Besides CEL evaluation raising an error explicitly, CEL program returning a type other than
// the ``string``, or not returning anything, are considered an error as well.
//
// [#comment:TODO(sergiitk): When implemented, add the extension tag.]
message CelExtractString {
// The CEL expression used to extract a string from the CEL environment.
// the "subject string") that should be replaced.
CelExpression expr_extract = 1 [(validate.rules).message = {required: true}];

// If CEL expression evaluates to an error, this value is be returned to the caller.
// If not set, the error is propagated to the caller.
google.protobuf.StringValue default_value = 2;
}

0 comments on commit 54924e0

Please sign in to comment.