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 May 9, 2022
1 parent fd316be commit 97ee0c7
Show file tree
Hide file tree
Showing 17 changed files with 689 additions and 47 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ Please see the [Envoy documentation](https://www.envoyproxy.io/docs/envoy/latest
- Feature: It is now possible to set `propagation_modes` in the `TracingService` config when using
lightstep as the driver. (Thanks to <a href="https://github.com/psalaberria002">Paul</a>!) ([#4179])

- 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
[#4181]: https://github.com/emissary-ingress/emissary/pull/4181

## [2.2.2] TBD
[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 @@ -48,6 +48,16 @@ items:
github:
- title: "#4179"
link: https://github.com/emissary-ingress/emissary/pull/4179
- 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: 'TBD'
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 @@ -3727,6 +3727,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 @@ -3798,6 +3841,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 @@ -3818,6 +3904,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
132 changes: 131 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,133 @@ func TestConvert(t *testing.T) {
}
})
}

func TestConvertTracingService(t *testing.T) {

scheme := BuildScheme()

// v3alpha1 to v2

// only custom_tags set
o := &v2.TracingServiceSpec{}
scheme.Convert(&v3alpha1.TracingServiceSpec{
AmbassadorID: v3alpha1.AmbassadorID{},
CustomTags: []v3alpha1.TracingCustomTag{
{
Tag: "hola",
Header: &v3alpha1.TracingCustomTagTypeRequestHeader{
Name: "hola",
},
},
},
}, o, nil)
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{}
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 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{}
scheme.Convert(&v3alpha1.TracingServiceSpec{
AmbassadorID: v3alpha1.AmbassadorID{},
DeprecatedTagHeaders: []string{"hello"},
}, o3, nil)
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{}
scheme.Convert(&v2.TracingServiceSpec{
AmbassadorID: v2.AmbassadorID{},
TagHeaders: []string{"hola"},
}, out, nil)
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{}
scheme.Convert(&v2.TracingServiceSpec{
AmbassadorID: v2.AmbassadorID{},
V3CustomTags: []v3alpha1.TracingCustomTag{
{
Tag: "hello",
Header: &v3alpha1.TracingCustomTagTypeRequestHeader{
Name: "hello",
},
},
},
}, out2, nil)
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{}
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 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))
}

}
89 changes: 89 additions & 0 deletions pkg/api/getambassador.io/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,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 @@ -3856,6 +3899,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 @@ -3876,6 +3962,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
Loading

0 comments on commit 97ee0c7

Please sign in to comment.