istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/xds/monitoring.go (about)

     1  // Copyright Istio Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package xds
    16  
    17  import (
    18  	"time"
    19  
    20  	istiolog "istio.io/istio/pkg/log"
    21  	"istio.io/istio/pkg/model"
    22  	"istio.io/istio/pkg/monitoring"
    23  )
    24  
    25  var (
    26  	Log = istiolog.RegisterScope("ads", "ads debugging")
    27  	log = Log
    28  
    29  	errTag  = monitoring.CreateLabel("err")
    30  	nodeTag = monitoring.CreateLabel("node")
    31  	typeTag = monitoring.CreateLabel("type")
    32  
    33  	TotalXDSInternalErrors = monitoring.NewSum(
    34  		"pilot_total_xds_internal_errors",
    35  		"Total number of internal XDS errors in pilot.",
    36  	)
    37  
    38  	ExpiredNonce = monitoring.NewSum(
    39  		"pilot_xds_expired_nonce",
    40  		"Total number of XDS requests with an expired nonce.",
    41  	)
    42  
    43  	// pilot_total_xds_rejects should be used instead. This is for backwards compatibility
    44  	cdsReject = monitoring.NewGauge(
    45  		"pilot_xds_cds_reject",
    46  		"Pilot rejected CDS configs.",
    47  	)
    48  
    49  	// pilot_total_xds_rejects should be used instead. This is for backwards compatibility
    50  	edsReject = monitoring.NewGauge(
    51  		"pilot_xds_eds_reject",
    52  		"Pilot rejected EDS.",
    53  	)
    54  
    55  	// pilot_total_xds_rejects should be used instead. This is for backwards compatibility
    56  	ldsReject = monitoring.NewGauge(
    57  		"pilot_xds_lds_reject",
    58  		"Pilot rejected LDS.",
    59  	)
    60  
    61  	// pilot_total_xds_rejects should be used instead. This is for backwards compatibility
    62  	rdsReject = monitoring.NewGauge(
    63  		"pilot_xds_rds_reject",
    64  		"Pilot rejected RDS.",
    65  	)
    66  
    67  	totalXDSRejects = monitoring.NewSum(
    68  		"pilot_total_xds_rejects",
    69  		"Total number of XDS responses from pilot rejected by proxy.",
    70  	)
    71  
    72  	ResponseWriteTimeouts = monitoring.NewSum(
    73  		"pilot_xds_write_timeout",
    74  		"Pilot XDS response write timeouts.",
    75  	)
    76  
    77  	sendTime = monitoring.NewDistribution(
    78  		"pilot_xds_send_time",
    79  		"Total time in seconds Pilot takes to send generated configuration.",
    80  		[]float64{.01, .1, 1, 3, 5, 10, 20, 30},
    81  	)
    82  )
    83  
    84  func IncrementXDSRejects(xdsType string, node, errCode string) {
    85  	totalXDSRejects.With(typeTag.Value(model.GetMetricType(xdsType))).Increment()
    86  	switch xdsType {
    87  	case model.ListenerType:
    88  		ldsReject.With(nodeTag.Value(node), errTag.Value(errCode)).Increment()
    89  	case model.ClusterType:
    90  		cdsReject.With(nodeTag.Value(node), errTag.Value(errCode)).Increment()
    91  	case model.EndpointType:
    92  		edsReject.With(nodeTag.Value(node), errTag.Value(errCode)).Increment()
    93  	case model.RouteType:
    94  		rdsReject.With(nodeTag.Value(node), errTag.Value(errCode)).Increment()
    95  	}
    96  }
    97  
    98  func RecordSendTime(duration time.Duration) {
    99  	sendTime.Record(duration.Seconds())
   100  }