blob: 9e5d095b3061b0375351bc90dda57cc91cc89028 [file] [log] [blame]
//go:build integ
// +build integ
// Copyright Istio Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package server
import (
"errors"
"fmt"
"testing"
"time"
)
import (
"github.com/apache/dubbo-go-pixiu/pkg/test/framework"
"github.com/apache/dubbo-go-pixiu/pkg/test/framework/components/istio"
"github.com/apache/dubbo-go-pixiu/pkg/test/framework/label"
"github.com/apache/dubbo-go-pixiu/pkg/test/framework/resource"
"github.com/apache/dubbo-go-pixiu/pkg/test/util/retry"
"github.com/apache/dubbo-go-pixiu/tests/integration/telemetry/tracing"
)
// TestProxyTracing exercises the trace generation features of Istio, based on the Envoy Trace driver for zipkin.
// The test verifies that all expected spans (a client span and a server span for each service call in the sample bookinfo app)
// are generated and that they are all a part of the same distributed trace with correct hierarchy and name.
//
// More information on distributed tracing can be found here: https://istio.io/docs/tasks/telemetry/distributed-tracing/zipkin/
func TestProxyTracing(t *testing.T) {
framework.NewTest(t).
Features("observability.telemetry.tracing.server").
Run(func(t framework.TestContext) {
appNsInst := tracing.GetAppNamespace()
// TODO fix tracing tests in multi-network https://github.com/istio/istio/issues/28890
for _, cluster := range t.Clusters().ByNetwork()[t.Clusters().Default().NetworkName()] {
t.NewSubTest(cluster.StableName()).Run(func(t framework.TestContext) {
retry.UntilSuccessOrFail(t, func() error {
err := tracing.SendTraffic(t, nil, cluster)
if err != nil {
return fmt.Errorf("cannot send traffic from cluster %s: %v", cluster.Name(), err)
}
traces, err := tracing.GetZipkinInstance().QueryTraces(300,
fmt.Sprintf("server.%s.svc.cluster.local:80/*", appNsInst.Name()), "")
if err != nil {
return fmt.Errorf("cannot get traces from zipkin: %v", err)
}
if !tracing.VerifyEchoTraces(t, appNsInst.Name(), cluster.Name(), traces) {
return errors.New("cannot find expected traces")
}
return nil
}, retry.Delay(3*time.Second), retry.Timeout(80*time.Second))
})
}
})
}
func TestMain(m *testing.M) {
framework.NewSuite(m).
Label(label.CustomSetup).
Setup(istio.Setup(tracing.GetIstioInstance(), setupConfig)).
Setup(tracing.TestSetup).
Run()
}
func setupConfig(ctx resource.Context, cfg *istio.Config) {
if cfg == nil {
return
}
cfg.Values["meshConfig.enableTracing"] = "true"
cfg.Values["pilot.traceSampling"] = "100.0"
}