...

Source file src/google.golang.org/grpc/orca/orca.go

Documentation: google.golang.org/grpc/orca

     1  /*
     2   * Copyright 2022 gRPC authors.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  // Package orca implements Open Request Cost Aggregation, which is an open
    18  // standard for request cost aggregation and reporting by backends and the
    19  // corresponding aggregation of such reports by L7 load balancers (such as
    20  // Envoy) on the data plane. In a proxyless world with gRPC enabled
    21  // applications, aggregation of such reports will be done by the gRPC client.
    22  //
    23  // # Experimental
    24  //
    25  // Notice: All APIs is this package are EXPERIMENTAL and may be changed or
    26  // removed in a later release.
    27  package orca
    28  
    29  import (
    30  	"google.golang.org/grpc/grpclog"
    31  	"google.golang.org/grpc/internal/balancerload"
    32  	"google.golang.org/grpc/metadata"
    33  	"google.golang.org/grpc/orca/internal"
    34  )
    35  
    36  var logger = grpclog.Component("orca-backend-metrics")
    37  
    38  // loadParser implements the Parser interface defined in `internal/balancerload`
    39  // package. This interface is used by the client stream to parse load reports
    40  // sent by the server in trailer metadata. The parsed loads are then sent to
    41  // balancers via balancer.DoneInfo.
    42  //
    43  // The grpc package cannot directly call toLoadReport() as that would cause an
    44  // import cycle. Hence this roundabout method is used.
    45  type loadParser struct{}
    46  
    47  func (loadParser) Parse(md metadata.MD) any {
    48  	lr, err := internal.ToLoadReport(md)
    49  	if err != nil {
    50  		logger.Infof("Parse failed: %v", err)
    51  	}
    52  	return lr
    53  }
    54  
    55  func init() {
    56  	balancerload.SetParser(loadParser{})
    57  }
    58  

View as plain text