dubbo.apache.org/dubbo-go/v3@v3.1.1/metrics/rpc/event.go (about)

     1  /*
     2   * Licensed to the Apache Software Foundation (ASF) under one or more
     3   * contributor license agreements.  See the NOTICE file distributed with
     4   * this work for additional information regarding copyright ownership.
     5   * The ASF licenses this file to You under the Apache License, Version 2.0
     6   * (the "License"); you may not use this file except in compliance with
     7   * the License.  You may obtain a copy of the License at
     8   *
     9   *     http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package rpc
    19  
    20  import (
    21  	"time"
    22  )
    23  
    24  import (
    25  	"dubbo.apache.org/dubbo-go/v3/common/constant"
    26  	"dubbo.apache.org/dubbo-go/v3/metrics"
    27  	"dubbo.apache.org/dubbo-go/v3/protocol"
    28  )
    29  
    30  // metricsEvent is the event defined for rpc metrics
    31  type metricsEvent struct {
    32  	name       metricsName
    33  	invoker    protocol.Invoker
    34  	invocation protocol.Invocation
    35  	costTime   time.Duration
    36  	result     protocol.Result
    37  }
    38  
    39  // Type returns the type of the event, it is used for metrics bus to dispatch the event to rpc collector
    40  func (m metricsEvent) Type() string {
    41  	return constant.MetricsRpc
    42  }
    43  
    44  type metricsName uint8
    45  
    46  const (
    47  	BeforeInvoke metricsName = iota
    48  	AfterInvoke
    49  )
    50  
    51  func NewBeforeInvokeEvent(invoker protocol.Invoker, invocation protocol.Invocation) metrics.MetricsEvent {
    52  	return &metricsEvent{
    53  		name:       BeforeInvoke,
    54  		invoker:    invoker,
    55  		invocation: invocation,
    56  	}
    57  }
    58  
    59  func NewAfterInvokeEvent(invoker protocol.Invoker, invocation protocol.Invocation, costTime time.Duration, result protocol.Result) metrics.MetricsEvent {
    60  	return &metricsEvent{
    61  		name:       AfterInvoke,
    62  		invoker:    invoker,
    63  		invocation: invocation,
    64  		costTime:   costTime,
    65  		result:     result,
    66  	}
    67  }