istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tests/integration/telemetry/tracing/zipkin/server_tracing_test.go (about)

     1  //go:build integ
     2  // +build integ
     3  
     4  // Copyright Istio Authors. All Rights Reserved.
     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 zipkin
    19  
    20  import (
    21  	"errors"
    22  	"fmt"
    23  	"testing"
    24  	"time"
    25  
    26  	"istio.io/istio/pkg/test/framework"
    27  	"istio.io/istio/pkg/test/util/retry"
    28  	"istio.io/istio/tests/integration/telemetry/tracing"
    29  )
    30  
    31  // TestServerTracing exercises the trace generation features of Istio, based on the Envoy Trace driver for zipkin.
    32  // The test verifies that all expected spans (a client span and a server span for each service call in the sample bookinfo app)
    33  // are generated and that they are all a part of the same distributed trace with correct hierarchy and name.
    34  //
    35  // More information on distributed tracing can be found here: https://istio.io/docs/tasks/telemetry/distributed-tracing/zipkin/
    36  func TestServerTracing(t *testing.T) {
    37  	framework.NewTest(t).
    38  		Run(func(t framework.TestContext) {
    39  			appNsInst := tracing.GetAppNamespace()
    40  			for _, cluster := range t.Clusters().ByNetwork()[t.Clusters().Default().NetworkName()] {
    41  				t.NewSubTest(cluster.StableName()).Run(func(t framework.TestContext) {
    42  					retry.UntilSuccessOrFail(t, func() error {
    43  						err := tracing.SendTraffic(t, nil, cluster)
    44  						if err != nil {
    45  							return fmt.Errorf("cannot send traffic from cluster %s: %v", cluster.Name(), err)
    46  						}
    47  						traces, err := tracing.GetZipkinInstance().QueryTraces(300,
    48  							fmt.Sprintf("server.%s.svc.cluster.local:80/*", appNsInst.Name()), "")
    49  						if err != nil {
    50  							return fmt.Errorf("cannot get traces from zipkin: %v", err)
    51  						}
    52  						if !tracing.VerifyEchoTraces(t, appNsInst.Name(), cluster.Name(), traces) {
    53  							return errors.New("cannot find expected traces")
    54  						}
    55  						return nil
    56  					}, retry.Delay(3*time.Second), retry.Timeout(80*time.Second))
    57  				})
    58  			}
    59  		})
    60  }