Skip to content

Commit

Permalink
Allow setting custom_tags for traces
Browse files Browse the repository at this point in the history
It allows setting trace tags based on
literal values, environment variables, or request headers.

Based on https://www.envoyproxy.io/docs/envoy/latest/api-v3/type/tracing/v3/custom_tag.proto#custom-tag

Signed-off-by: Paul Salaberria <[email protected]>
  • Loading branch information
psalaberria002 committed Jun 7, 2022
1 parent e912763 commit af92682
Show file tree
Hide file tree
Showing 17 changed files with 710 additions and 47 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ it will be removed; but as it won't be user-visible this isn't considered a brea
`HTTP_JSON_V1` when explicitly setting the `AMBASSADOR_ENVOY_API_VERSION=V2` environment variable
to force use of xDS v2 to configure Envoy.

- Feature: It is now possible to set `custom_tags` in the `TracingService`. Trace tags can be set
based on literal values, environment variables, or request headers. (Thanks to <a
href="https://github.com/psalaberria002">Paul</a>!) ([#4181])

[#4179]: https://github.com/emissary-ingress/emissary/pull/4179
[#1743]: https://github.com/emissary-ingress/emissary/issues/1743
[#4181]: https://github.com/emissary-ingress/emissary/pull/4181

## [2.2.2] February 25, 2022
[2.2.2]: https://github.com/emissary-ingress/emissary/compare/v2.2.1...v2.2.2
Expand Down
10 changes: 10 additions & 0 deletions docs/releaseNotes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ items:
<code>HTTP_JSON_V1</code> when explicitly setting the
<code>AMBASSADOR_ENVOY_API_VERSION=V2</code> environment variable to force use of xDS v2
to configure Envoy.
- title: Allow setting custom_tags for traces
type: feature
body: >-
It is now possible to set <code>custom_tags</code> in the
<code>TracingService</code>. Trace tags can be set based on
literal values, environment variables, or request headers.
(Thanks to <a href="https://github.com/psalaberria002">Paul</a>!)
github:
- title: "#4181"
link: https://github.com/emissary-ingress/emissary/pull/4181

- version: 2.2.2
date: '2022-02-25'
Expand Down
89 changes: 89 additions & 0 deletions manifests/emissary/emissary-crds.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -3754,6 +3754,49 @@ spec:
items:
type: string
type: array
v3CustomTags:
items:
properties:
environment:
description: Environment explicitly specifies the protocol stack
to set up. Exactly one of Literal, Environment or Header must
be supplied.
properties:
default_value:
type: string
name:
type: string
required:
- name
type: object
literal:
description: Literal explicitly specifies the protocol stack
to set up. Exactly one of Literal, Environment or Header must
be supplied.
properties:
value:
type: string
required:
- value
type: object
request_header:
description: Header explicitly specifies the protocol stack
to set up. Exactly one of Literal, Environment or Header must
be supplied.
properties:
default_value:
type: string
name:
type: string
required:
- name
type: object
tag:
type: string
required:
- tag
type: object
type: array
v3StatsName:
type: string
required:
Expand Down Expand Up @@ -3825,6 +3868,49 @@ spec:
trace_id_128bit:
type: boolean
type: object
custom_tags:
items:
properties:
environment:
description: Environment explicitly specifies the protocol stack
to set up. Exactly one of Literal, Environment or Header must
be supplied.
properties:
default_value:
type: string
name:
type: string
required:
- name
type: object
literal:
description: Literal explicitly specifies the protocol stack
to set up. Exactly one of Literal, Environment or Header must
be supplied.
properties:
value:
type: string
required:
- value
type: object
request_header:
description: Header explicitly specifies the protocol stack
to set up. Exactly one of Literal, Environment or Header must
be supplied.
properties:
default_value:
type: string
name:
type: string
required:
- name
type: object
tag:
type: string
required:
- tag
type: object
type: array
driver:
enum:
- lightstep
Expand All @@ -3845,6 +3931,9 @@ spec:
stats_name:
type: string
tag_headers:
description: 'tag_headers is deprecated. Use custom_tags instead.
`tag_headers: ["header"]` can be defined as `custom_tags: [{"request_header":
{"name": "header"}}]`.'
items:
type: string
type: array
Expand Down
150 changes: 149 additions & 1 deletion pkg/api/getambassador.io/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"sigs.k8s.io/yaml"

"github.com/datawire/ambassador/v2/pkg/api/getambassador.io/v2"
v2 "github.com/datawire/ambassador/v2/pkg/api/getambassador.io/v2"
"github.com/datawire/ambassador/v2/pkg/api/getambassador.io/v3alpha1"
)

Expand Down Expand Up @@ -146,3 +146,151 @@ func TestConvert(t *testing.T) {
}
})
}

func TestConvertTracingService(t *testing.T) {

scheme := BuildScheme()

// v3alpha1 to v2

// only custom_tags set
o := &v2.TracingServiceSpec{}
err := scheme.Convert(&v3alpha1.TracingServiceSpec{
AmbassadorID: v3alpha1.AmbassadorID{},
CustomTags: []v3alpha1.TracingCustomTag{
{
Tag: "hola",
Header: &v3alpha1.TracingCustomTagTypeRequestHeader{
Name: "hola",
},
},
},
}, o, nil)
if err != nil {
t.Errorf("conversion failed. %v", err)
}
if len(o.V3CustomTags) != 1 {
t.Errorf("got %d; want 1", len(o.V3CustomTags))
}
if len(o.TagHeaders) != 0 {
t.Errorf("got %d; want 0", len(o.TagHeaders))
}

// both custom_tags and tag_headers set
o2 := &v2.TracingServiceSpec{}
err = scheme.Convert(&v3alpha1.TracingServiceSpec{
AmbassadorID: v3alpha1.AmbassadorID{},
DeprecatedTagHeaders: []string{"hello"},
CustomTags: []v3alpha1.TracingCustomTag{
{
Tag: "hola",
Header: &v3alpha1.TracingCustomTagTypeRequestHeader{
Name: "hola",
},
},
{
Tag: "env",
Environment: &v3alpha1.TracingCustomTagTypeEnvironment{
Name: "env",
},
},
},
}, o2, nil)
if err != nil {
t.Errorf("conversion failed. %v", err)
}
if len(o2.V3CustomTags) != 2 {
t.Errorf("got %d; want 2", len(o2.V3CustomTags))
}
if len(o2.TagHeaders) != 0 {
t.Errorf("got %d; want 0", len(o2.TagHeaders))
}

// only tag_headers set
o3 := &v2.TracingServiceSpec{}
err = scheme.Convert(&v3alpha1.TracingServiceSpec{
AmbassadorID: v3alpha1.AmbassadorID{},
DeprecatedTagHeaders: []string{"hello"},
}, o3, nil)
if err != nil {
t.Errorf("conversion failed. %v", err)
}
if len(o3.V3CustomTags) != 1 {
t.Errorf("got %d; want 1", len(o3.V3CustomTags))
}
if len(o3.TagHeaders) != 0 {
t.Errorf("got %d; want 0", len(o3.TagHeaders))
}

// v2 to v3alpha1

// only tag_headers set
out := &v3alpha1.TracingServiceSpec{}
err = scheme.Convert(&v2.TracingServiceSpec{
AmbassadorID: v2.AmbassadorID{},
TagHeaders: []string{"hola"},
}, out, nil)
if err != nil {
t.Errorf("conversion failed. %v", err)
}
if len(out.CustomTags) != 1 {
t.Errorf("got %d; want 1", len(out.CustomTags))
}
if len(out.DeprecatedTagHeaders) != 0 {
t.Errorf("got %d; want 0", len(out.DeprecatedTagHeaders))
}

// only v3CustomTags set
out2 := &v3alpha1.TracingServiceSpec{}
err = scheme.Convert(&v2.TracingServiceSpec{
AmbassadorID: v2.AmbassadorID{},
V3CustomTags: []v3alpha1.TracingCustomTag{
{
Tag: "hello",
Header: &v3alpha1.TracingCustomTagTypeRequestHeader{
Name: "hello",
},
},
},
}, out2, nil)
if err != nil {
t.Errorf("conversion failed. %v", err)
}
if len(out2.CustomTags) != 1 {
t.Errorf("got %d; want 1", len(out2.CustomTags))
}
if len(out2.DeprecatedTagHeaders) != 0 {
t.Errorf("got %d; want 0", len(out2.DeprecatedTagHeaders))
}

// both custom_tags and tag_headers set
out3 := &v3alpha1.TracingServiceSpec{}
err = scheme.Convert(&v2.TracingServiceSpec{
AmbassadorID: v2.AmbassadorID{},
TagHeaders: []string{"hola"},
V3CustomTags: []v3alpha1.TracingCustomTag{
{
Tag: "hello",
Header: &v3alpha1.TracingCustomTagTypeRequestHeader{
Name: "hello",
},
},
{
Tag: "hello2",
Environment: &v3alpha1.TracingCustomTagTypeEnvironment{
Name: "hello2",
},
},
},
}, out3, nil)
if err != nil {
t.Errorf("conversion failed. %v", err)
}
if len(out3.CustomTags) != 2 {
t.Errorf("got %d; want 2", len(out3.CustomTags))
}
if len(out3.DeprecatedTagHeaders) != 0 {
t.Errorf("got %d; want 0", len(out3.DeprecatedTagHeaders))
}

}
Loading

0 comments on commit af92682

Please sign in to comment.