Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions galley/pkg/metadata/kube/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,17 @@ func init() {
Converter: converter.Get("identity"),
})

b.Add(schema.ResourceSpec{
Kind: "zipkin",
ListKind: "zipkinList",
Singular: "zipkin",
Plural: "zipkins",
Version: "v1alpha2",
Group: "config.istio.io",
Target: metadata.Types.Get("istio/config/v1alpha2/legacy/zipkins"),
Converter: converter.Get("identity"),
})

b.Add(schema.ResourceSpec{
Kind: "template",
ListKind: "templateList",
Expand Down
6 changes: 6 additions & 0 deletions galley/pkg/metadata/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ var (
// Tracespan metadata
Tracespan resource.Info

// Zipkin metadata
Zipkin resource.Info

// Template metadata
Template resource.Info

Expand Down Expand Up @@ -329,6 +332,9 @@ func init() {
Tracespan = b.Register(
"istio/config/v1alpha2/legacy/tracespans",
"type.googleapis.com/type.googleapis.com/google.protobuf.Struct")
Zipkin = b.Register(
"istio/config/v1alpha2/legacy/zipkins",
"type.googleapis.com/type.googleapis.com/google.protobuf.Struct")
Template = b.Register(
"istio/config/v1alpha2/templates",
"type.googleapis.com/type.googleapis.com/google.protobuf.Struct")
Expand Down
9 changes: 9 additions & 0 deletions galley/tools/gen-meta/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,12 @@ resources:
proto: "type.googleapis.com/google.protobuf.Struct"
protoPackage: "github.com/gogo/protobuf/types"
collection: "istio/config/v1alpha2/legacy/edges"

- kind: "zipkin"
singular: "zipkin"
plural: "zipkins"
group: "config.istio.io"
version: "v1alpha2"
proto: "type.googleapis.com/google.protobuf.Struct"
protoPackage: "github.com/gogo/protobuf/types"
collection: "istio/config/v1alpha2/legacy/zipkins"
22 changes: 22 additions & 0 deletions install/kubernetes/helm/istio-init/files/crd-11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,25 @@ spec:
scope: Namespaced
version: v1alpha3
---
kind: CustomResourceDefinition
apiVersion: apiextensions.k8s.io/v1beta1
metadata:
name: zipkins.config.istio.io
annotations:
"helm.sh/hook": crd-install
labels:
app: mixer
package: zipkin
istio: mixer-adapter
spec:
group: config.istio.io
names:
kind: zipkin
plural: zipkins
singular: zipkin
categories:
- istio-io
- policy-istio-io
scope: Namespaced
version: v1alpha2
---
2 changes: 2 additions & 0 deletions mixer/adapter/inventory.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
stackdriver "istio.io/istio/mixer/adapter/stackdriver"
statsd "istio.io/istio/mixer/adapter/statsd"
stdio "istio.io/istio/mixer/adapter/stdio"
zipkin "istio.io/istio/mixer/adapter/zipkin"
adptr "istio.io/istio/mixer/pkg/adapter"
)

Expand All @@ -63,5 +64,6 @@ func Inventory() []adptr.InfoFn {
stackdriver.GetInfo,
statsd.GetInfo,
stdio.GetInfo,
zipkin.GetInfo,
}
}
1 change: 1 addition & 0 deletions mixer/adapter/inventory.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ solarwinds: "istio.io/istio/mixer/adapter/solarwinds"
stackdriver: "istio.io/istio/mixer/adapter/stackdriver"
statsd: "istio.io/istio/mixer/adapter/statsd"
stdio: "istio.io/istio/mixer/adapter/stdio"
zipkin: "istio.io/istio/mixer/adapter/zipkin"
5 changes: 3 additions & 2 deletions mixer/adapter/signalfx/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
octrace "go.opencensus.io/trace"

"istio.io/istio/mixer/pkg/adapter"
"istio.io/istio/mixer/pkg/adapter/opencensus"
"istio.io/istio/mixer/pkg/attribute"
"istio.io/istio/mixer/template/tracespan"
)
Expand Down Expand Up @@ -122,11 +123,11 @@ func (th *tracinghandler) HandleTraceSpan(ctx context.Context, values []*tracesp
}

func (th *tracinghandler) shouldSend(span *tracespan.Instance) bool {
parentContext, ok := adapter.ExtractParentContext(span.TraceId, span.ParentSpanId)
parentContext, ok := opencensus.ExtractParentContext(span.TraceId, span.ParentSpanId)
if !ok {
return false
}
spanContext, ok := adapter.ExtractSpanContext(span.SpanId, parentContext)
spanContext, ok := opencensus.ExtractSpanContext(span.SpanId, parentContext)
if !ok {
return false
}
Expand Down
152 changes: 11 additions & 141 deletions mixer/adapter/stackdriver/trace/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,27 @@ package trace

import (
"context"
"fmt"

"go.opencensus.io/plugin/ochttp"
"go.opencensus.io/trace"

"istio.io/istio/mixer/adapter/stackdriver/config"
"istio.io/istio/mixer/adapter/stackdriver/helper"
"istio.io/istio/mixer/pkg/adapter"
"istio.io/istio/mixer/pkg/adapter/opencensus"
"istio.io/istio/mixer/template/tracespan"
)

type (
builder struct {
types map[string]*tracespan.Type
mg helper.MetadataGenerator
cfg *config.Params
}

handler struct {
te trace.Exporter
sampler trace.Sampler
}
)
type builder struct {
types map[string]*tracespan.Type
mg helper.MetadataGenerator
cfg *config.Params
}

var (
// compile-time assertion that we implement the interfaces we promise
_ tracespan.HandlerBuilder = &builder{}
_ tracespan.Handler = &handler{}

pad = [8]byte{0x3f, 0x6a, 0x2e, 0xc3, 0xc8, 0x10, 0xc2, 0xab}
)

const attrHTTPStatusCode = "http.status_code"

// NewBuilder returns a builder implementing the tracespan.HandlerBuilder interface.
func NewBuilder(mg helper.MetadataGenerator) tracespan.HandlerBuilder {
return &builder{mg: mg}
Expand Down Expand Up @@ -85,132 +72,15 @@ func (b *builder) Build(ctx context.Context, env adapter.Env) (adapter.Handler,
return nil, err
}

h := &handler{
te: exporter,
}
traceCfg := b.cfg.Trace
var sampler trace.Sampler
if traceCfg != nil {
if sampleProbability := traceCfg.SampleProbability; sampleProbability > 0 {
h.sampler = trace.ProbabilitySampler(traceCfg.SampleProbability)
}
}
return h, nil
}

func (h *handler) HandleTraceSpan(_ context.Context, values []*tracespan.Instance) (retErr error) {
if h.sampler == nil {
// Tracing is not configured.
return nil
}

numExported := 0
for _, val := range values {
parentContext, ok := adapter.ExtractParentContext(val.TraceId, val.ParentSpanId)
if !ok {
continue
}
spanContext, ok := adapter.ExtractSpanContext(val.SpanId, parentContext)
if !ok {
continue
}

decision := h.sampler(trace.SamplingParameters{
ParentContext: parentContext,
TraceID: spanContext.TraceID,
SpanID: spanContext.SpanID,
Name: val.SpanName,
HasRemoteParent: true,
})

if !decision.Sample {
continue
}
spanContext.TraceOptions = trace.TraceOptions(1 /*sampled*/)

span := buildSpanData(val, parentContext, spanContext)
h.te.ExportSpan(span)
numExported++
}

if numExported > 0 {
h.tryFlush()
}

return
}

func buildSpanData(val *tracespan.Instance, parentContext trace.SpanContext, spanContext trace.SpanContext) *trace.SpanData {
attributes := make(map[string]interface{})
for k, v := range val.SpanTags {
switch x := v.(type) {
case string, int64, float64:
attributes[k] = x
default:
attributes[k] = fmt.Sprintf("%v", x)
}
}

var status trace.Status
if val.HttpStatusCode > 0 {
if _, ok := attributes[attrHTTPStatusCode]; !ok {
attributes[attrHTTPStatusCode] = val.HttpStatusCode
}
status = ochttp.TraceStatus(int(val.HttpStatusCode), "")
}

spanKind := trace.SpanKindServer
parentSpanID := parentContext.SpanID
spanID := spanContext.SpanID
if val.ClientSpan {
spanKind = trace.SpanKindClient
// If this is a client span and rewriteClientSpanId is true, deterministically create a new span
// ID and rewrite span id to that one. This id should also be used as server span's parent span
// id.
if val.RewriteClientSpanId {
spanID = rewriteSpanID(spanID)
sampler = trace.ProbabilitySampler(traceCfg.SampleProbability)
}
} else if val.RewriteClientSpanId {
// If this is a server span and rewriteClientSpanId is true, deterministically create a new span
// ID and rewrite parent id to that one, which makes this span attached to the client span as a
// child span.
parentSpanID = rewriteSpanID(spanID)
}
return &trace.SpanData{
SpanKind: spanKind,
Name: val.SpanName,
StartTime: val.StartTime,
EndTime: val.EndTime,
ParentSpanID: parentSpanID,
SpanContext: trace.SpanContext{
TraceOptions: spanContext.TraceOptions,
TraceID: spanContext.TraceID,
SpanID: spanID,
},
HasRemoteParent: true,
Status: status,
Attributes: attributes,
newExporter := func(name string, endpoint string) trace.Exporter {
return exporter
}
}

// rewriteSpanID deterministically creates a new span id base on the given span id by XOR with a pad.
func rewriteSpanID(spanID trace.SpanID) trace.SpanID {
var newID trace.SpanID
for i, b := range spanID {
newID[i] = b ^ pad[i]
}
return newID
}

func (h *handler) Close() error {
return nil
}

func (h *handler) tryFlush() {
if flusher, ok := h.te.(flusher); ok {
flusher.Flush()
}
}

type flusher interface {
Flush()
return opencensus.NewTraceHandler(newExporter, sampler), nil
}
Loading