istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/telemetry/policy/traffic_registry_only_test.go (about)

     1  //go:build integ
     2  // +build integ
     3  
     4  // Copyright Istio Authors
     5  //
     6  // Licensed under the Apache License, Version 2.0 (the "License");
     7  // you may not use this file except in compliance with the License.
     8  // You may obtain a copy of the License at
     9  //
    10  //     http://www.apache.org/licenses/LICENSE-2.0
    11  //
    12  // Unless required by applicable law or agreed to in writing, software
    13  // distributed under the License is distributed on an "AS IS" BASIS,
    14  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  // See the License for the specific language governing permissions and
    16  // limitations under the License.
    17  
    18  package policy
    19  
    20  import (
    21  	"net/http"
    22  	"testing"
    23  
    24  	"istio.io/istio/pkg/test/framework/components/prometheus"
    25  )
    26  
    27  func TestOutboundTrafficPolicy_RegistryOnly(t *testing.T) {
    28  	cases := []*TestCase{
    29  		{
    30  			Name:     "HTTP Traffic",
    31  			PortName: "http",
    32  			Expected: Expected{
    33  				Query: prometheus.Query{
    34  					Metric:      "istio_requests_total",
    35  					Aggregation: "sum",
    36  					Labels: map[string]string{
    37  						"reporter":                 "source",
    38  						"destination_service_name": "BlackHoleCluster",
    39  						"response_code":            "502",
    40  					},
    41  				},
    42  				StatusCode: http.StatusBadGateway,
    43  			},
    44  		},
    45  		{
    46  			Name:     "HTTPS Traffic",
    47  			PortName: "https",
    48  			Expected: Expected{
    49  				Query: prometheus.Query{
    50  					Metric:      "istio_tcp_connections_closed_total",
    51  					Aggregation: "sum",
    52  					Labels: map[string]string{
    53  						"destination_service_name": "BlackHoleCluster",
    54  					},
    55  				},
    56  			},
    57  		},
    58  		{
    59  			Name:     "HTTPS Traffic Conflict",
    60  			PortName: "https-conflict",
    61  			Expected: Expected{
    62  				Query: prometheus.Query{
    63  					Metric:      "istio_tcp_connections_closed_total",
    64  					Aggregation: "sum",
    65  					Labels: map[string]string{
    66  						"destination_service_name": "BlackHoleCluster",
    67  					},
    68  				},
    69  			},
    70  		},
    71  		{
    72  			Name:     "HTTP Traffic Egress",
    73  			PortName: "http",
    74  			Host:     "some-external-site.com",
    75  			Expected: Expected{
    76  				Query: prometheus.Query{
    77  					Metric:      "istio_requests_total",
    78  					Aggregation: "sum",
    79  					Labels: map[string]string{
    80  						"destination_service_name": "istio-egressgateway",
    81  						"response_code":            "200",
    82  					},
    83  				},
    84  				StatusCode: http.StatusOK,
    85  				RequestHeaders: map[string]string{
    86  					// We inject this header in the VirtualService
    87  					"Handled-By-Egress-Gateway": "true",
    88  				},
    89  			},
    90  		},
    91  		// TODO add HTTPS through gateway
    92  		{
    93  			Name:     "TCP",
    94  			PortName: "tcp",
    95  			Expected: Expected{
    96  				Query: prometheus.Query{
    97  					Metric:      "istio_tcp_connections_closed_total",
    98  					Aggregation: "sum",
    99  					Labels: map[string]string{
   100  						"reporter":                 "source",
   101  						"destination_service_name": "BlackHoleCluster",
   102  						"source_workload":          "client-v1",
   103  					},
   104  				},
   105  			},
   106  		},
   107  		{
   108  			Name:     "TCP Conflict",
   109  			PortName: "tcp-conflict",
   110  			Expected: Expected{
   111  				Query: prometheus.Query{
   112  					Metric:      "istio_tcp_connections_closed_total",
   113  					Aggregation: "sum",
   114  					Labels: map[string]string{
   115  						"reporter":                 "source",
   116  						"destination_service_name": "BlackHoleCluster",
   117  						"source_workload":          "client-v1",
   118  					},
   119  				},
   120  			},
   121  		},
   122  	}
   123  
   124  	// destination_service="BlackHoleCluster" does not get filled in when using sidecar scoping
   125  	RunExternalRequest(t, cases, prom, RegistryOnly)
   126  }