data

package
v0.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 31 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package data is used to test the trace service.

Index

Constants

View Source
const LicenseHeader = "# Licensed to Apache Software Foundation (ASF) under one or more contributor\n" +
	"# license agreements. See the NOTICE file distributed with\n" +
	"# this work for additional information regarding copyright\n" +
	"# ownership. Apache Software Foundation (ASF) licenses this file to you under\n" +
	"# the Apache License, Version 2.0 (the \"License\"); you may\n" +
	"# not use this file except in compliance with the License.\n" +
	"# You may obtain a copy of the License at\n" +
	"#\n" +
	"#     http://www.apache.org/licenses/LICENSE-2.0\n" +
	"#\n" +
	"# Unless required by applicable law or agreed to in writing,\n" +
	"# software distributed under the License is distributed on an\n" +
	"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
	"# KIND, either express or implied.  See the License for the\n" +
	"# specific language governing permissions and limitations\n" +
	"# under the License.\n\n"

LicenseHeader is the Apache 2.0 header (in YAML/properties comment form, trailing blank line included) that generated fixture files must carry so they pass the repo-wide license-eye scan. Both the generator and the response-capture writer prepend this to every file they produce; without it, regenerating the fixtures locally silently strips the header and would break `make license-check` (the bug uncovered by the vectorized-query branch's full `make test` run, which exercises the `./test/cases/...` path that CI normally skips).

Variables

View Source
var VerifyFn = func(innerGm gm.Gomega, sharedContext helpers.SharedContext, args helpers.Args) {
	i, err := inputFS.ReadFile("input/" + args.Input + ".yml")
	innerGm.Expect(err).NotTo(gm.HaveOccurred())
	query := &tracev1.QueryRequest{}
	helpers.UnmarshalYAML(i, query)
	if !args.WantErr {
		verifyQLWithRequest(innerGm, args, query, sharedContext.Connection)
	}
	query.TimeRange = helpers.TimeRange(args, sharedContext)
	query.Stages = args.Stages
	c := tracev1.NewTraceServiceClient(sharedContext.Connection)
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()
	resp, err := c.Query(ctx, query)
	if args.WantErr {
		if err == nil {
			g.Fail("expect error")
		}
		return
	}
	innerGm.Expect(err).NotTo(gm.HaveOccurred(), query.String())
	if args.WantEmpty {
		innerGm.Expect(resp.Traces).To(gm.BeEmpty(), func() string {
			var j []byte
			j, err = MarshalToJSONWithStringBytes(resp)
			if err != nil {
				return err.Error()
			}
			var y []byte
			y, err = yaml.JSONToYAML(j)
			if err != nil {
				return err.Error()
			}
			return string(y)
		})
		return
	}
	if args.Want == "" {
		args.Want = args.Input
	}
	ww, err := wantFS.ReadFile("want/" + args.Want + ".yml")
	innerGm.Expect(err).NotTo(gm.HaveOccurred())
	want := &tracev1.QueryResponse{}
	unmarshalYAMLWithSpanEncoding(ww, want)
	for i := range want.Traces {
		slices.SortFunc(want.Traces[i].Spans, func(a, b *tracev1.Span) int {
			return bytes.Compare(a.Span, b.Span)
		})
	}
	for i := range resp.Traces {
		slices.SortFunc(resp.Traces[i].Spans, func(a, b *tracev1.Span) int {
			return bytes.Compare(a.Span, b.Span)
		})
	}

	if args.DisOrder {

		slices.SortFunc(want.Traces, func(a, b *tracev1.Trace) int {
			if len(a.Spans) > 0 && len(b.Spans) > 0 && len(a.Spans[0].Tags) > 0 && len(b.Spans[0].Tags) > 0 {
				return strings.Compare(a.Spans[0].Tags[0].Value.GetStr().GetValue(), b.Spans[0].Tags[0].Value.GetStr().GetValue())
			}
			return 0
		})
		slices.SortFunc(resp.Traces, func(a, b *tracev1.Trace) int {
			if len(a.Spans) > 0 && len(b.Spans) > 0 && len(a.Spans[0].Tags) > 0 && len(b.Spans[0].Tags) > 0 {
				return strings.Compare(a.Spans[0].Tags[0].Value.GetStr().GetValue(), b.Spans[0].Tags[0].Value.GetStr().GetValue())
			}
			return 0
		})

		for _, trace := range want.Traces {
			slices.SortFunc(trace.Spans, func(a, b *tracev1.Span) int {
				if len(a.Tags) > 0 && len(b.Tags) > 0 {
					return strings.Compare(a.Tags[0].Value.GetStr().GetValue(), b.Tags[0].Value.GetStr().GetValue())
				}
				return 0
			})
		}
		for _, trace := range resp.Traces {
			slices.SortFunc(trace.Spans, func(a, b *tracev1.Span) int {
				if len(a.Tags) > 0 && len(b.Tags) > 0 {
					return strings.Compare(a.Tags[0].Value.GetStr().GetValue(), b.Tags[0].Value.GetStr().GetValue())
				}
				return 0
			})
		}
	}
	var extra []cmp.Option
	extra = append(extra, protocmp.IgnoreUnknown(),
		protocmp.Transform())
	success := innerGm.Expect(cmp.Equal(resp, want,
		extra...)).
		To(gm.BeTrue(), func() string {
			var j []byte
			j, err = MarshalToJSONWithStringBytes(resp)
			if err != nil {
				return err.Error()
			}
			var y []byte
			y, err = yaml.JSONToYAML(j)
			if err != nil {
				return err.Error()
			}
			return string(y)
		})
	if !success {
		return
	}
	query.Trace = true
	resp, err = c.Query(ctx, query)
	innerGm.Expect(err).NotTo(gm.HaveOccurred())
	innerGm.Expect(resp.TraceQueryResult).NotTo(gm.BeNil())
	innerGm.Expect(resp.TraceQueryResult.GetSpans()).NotTo(gm.BeEmpty())
}

VerifyFn verify whether the query response matches the wanted result.

Functions

func GetSpanDataAsString

func GetSpanDataAsString(span *tracev1.Span) string

GetSpanDataAsString extracts the span data as a string from a Span. This converts the raw bytes back to the original string value like "trace_001_span_1".

func MarshalToJSONWithStringBytes added in v0.11.0

func MarshalToJSONWithStringBytes(resp *tracev1.QueryResponse) ([]byte, error)

MarshalToJSONWithStringBytes marshals the QueryResponse to JSON with []byte fields as strings instead of base64.

func SeedAll added in v0.11.0

func SeedAll(conn *grpclib.ClientConn, baseTime time.Time, interval time.Duration)

SeedAll writes all trace fixtures used by the integration suite.

func Write

func Write(conn *grpclib.ClientConn, name string, baseTime time.Time, interval time.Duration)

Write writes trace data to the database.

func WriteMixed added in v0.10.0

func WriteMixed(conn *grpclib.ClientConn, baseTime time.Time, interval time.Duration, writeSpecs ...WriteSpec)

WriteMixed writes trace data in schema order first, and then in spec order.

func WriteToGroup

func WriteToGroup(conn *grpclib.ClientConn, name, group, fileName string, baseTime time.Time, interval time.Duration)

WriteToGroup writes trace data to a specific group.

Types

type WriteSpec added in v0.10.0

type WriteSpec struct {
	Metadata *commonv1.Metadata
	Spec     *tracev1.TagSpec
	DataFile string
}

WriteSpec defines the specification for writing trace data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL