Skip to content

Commit

Permalink
Add propagation_modes for the Lightstep Tracer
Browse files Browse the repository at this point in the history
The Lightstep tracer supports multiple propagation modes.
See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/trace/v3/lightstep.proto#enum-config-trace-v3-lightstepconfig-propagationmode

With this PR it is now possible to set a list of propagation modes in
the config field of the TracingService.

Signed-off-by: Paul Salaberria <[email protected]>
  • Loading branch information
psalaberria002 committed Apr 5, 2022
1 parent a9b94f4 commit 66c957e
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ Please see the [Envoy documentation](https://www.envoyproxy.io/docs/envoy/latest

- Security: Completely remove gdbm, pip, smtplib, and sqlite packages, as they are unused.

- 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])

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

## [2.2.1] February 22, 2022
[2.2.1]: https://github.com/emissary-ingress/emissary/compare/v2.2.0...v2.2.1

Expand Down
10 changes: 10 additions & 0 deletions docs/releaseNotes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ items:
type: security
body: >-
Completely remove gdbm, pip, smtplib, and sqlite packages, as they are unused.
- title: Allow setting propagation modes for Lightstep tracing
type: feature
body: >-
It is now possible to set <code>propagation_modes</code> in the
<code>TracingService</code> config when using lightstep as the driver.
(Thanks to <a href="https://github.com/psalaberria002">Paul</a>!)
github:
- title: "#4179"
link: https://github.com/emissary-ingress/emissary/pull/4179


- version: 2.2.1
date: '2022-02-22'
Expand Down
9 changes: 9 additions & 0 deletions manifests/emissary/emissary-crds.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -3773,6 +3773,15 @@ spec:
type: string
collector_hostname:
type: string
propagation_modes:
items:
enum:
- ENVOY
- LIGHTSTEP
- B3
- TRACE_CONTEXT
type: string
type: array
service_name:
type: string
shared_span_context:
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/getambassador.io/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3831,6 +3831,15 @@ spec:
type: string
collector_hostname:
type: string
propagation_modes:
items:
enum:
- ENVOY
- LIGHTSTEP
- B3
- TRACE_CONTEXT
type: string
type: array
service_name:
type: string
shared_span_context:
Expand Down
72 changes: 65 additions & 7 deletions pkg/api/getambassador.io/v2/zz_generated.conversion.go

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

14 changes: 9 additions & 5 deletions pkg/api/getambassador.io/v3alpha1/crd_tracingservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ type TraceSampling struct {
Overall *int `json:"overall,omitempty"`
}

// +kubebuilder:validation:Enum=ENVOY;LIGHTSTEP;B3;TRACE_CONTEXT
type PropagationMode string

type TraceConfig struct {
AccessTokenFile string `json:"access_token_file,omitempty"`
CollectorCluster string `json:"collector_cluster,omitempty"`
CollectorEndpoint string `json:"collector_endpoint,omitempty"`
// +kubebuilder:validation:Enum=HTTP_JSON_V1;HTTP_JSON;HTTP_PROTO
CollectorEndpointVersion string `json:"collector_endpoint_version,omitempty"`
CollectorHostname string `json:"collector_hostname,omitempty"`
TraceID128Bit *bool `json:"trace_id_128bit,omitempty"`
SharedSpanContext *bool `json:"shared_span_context,omitempty"`
ServiceName string `json:"service_name,omitempty"`
CollectorEndpointVersion string `json:"collector_endpoint_version,omitempty"`
CollectorHostname string `json:"collector_hostname,omitempty"`
PropagationModes []PropagationMode `json:"propagation_modes,omitempty"`
TraceID128Bit *bool `json:"trace_id_128bit,omitempty"`
SharedSpanContext *bool `json:"shared_span_context,omitempty"`
ServiceName string `json:"service_name,omitempty"`
}

// TracingServiceSpec defines the desired state of TracingService
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/getambassador.io/v3alpha1/zz_generated.deepcopy.go

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

9 changes: 9 additions & 0 deletions python/tests/integration/manifests/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,15 @@ spec:
type: string
collector_hostname:
type: string
propagation_modes:
items:
enum:
- ENVOY
- LIGHTSTEP
- B3
- TRACE_CONTEXT
type: string
type: array
service_name:
type: string
shared_span_context:
Expand Down
117 changes: 117 additions & 0 deletions python/tests/unit/test_tracing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from typing import Optional, TYPE_CHECKING

import logging
import pytest

from tests.selfsigned import TLSCerts
from tests.utils import assert_valid_envoy_config, module_and_mapping_manifests

logging.basicConfig(
level=logging.INFO,
format="%(asctime)s test %(levelname)s: %(message)s",
datefmt='%Y-%m-%d %H:%M:%S'
)

logger = logging.getLogger("ambassador")

from ambassador import Config, IR
from ambassador.envoy import EnvoyConfig
from ambassador.fetch import ResourceFetcher
from ambassador.utils import SecretHandler, SecretInfo

if TYPE_CHECKING:
from ambassador.ir.irresource import IRResource # pragma: no cover

class MockSecretHandler(SecretHandler):
def load_secret(self, resource: 'IRResource', secret_name: str, namespace: str) -> Optional[SecretInfo]:
return SecretInfo('fallback-self-signed-cert', 'ambassador', "mocked-fallback-secret",
TLSCerts["acook"].pubcert, TLSCerts["acook"].privkey, decode_b64=False)


def lightstep_tracing_service_manifest():
return """
---
apiVersion: getambassador.io/v3alpha1
kind: TracingService
metadata:
name: tracing
namespace: ambassador
spec:
service: lightstep:80
driver: lightstep
config:
access_token_file: /lightstep-credentials/access-token
propagation_modes: ["ENVOY", "TRACE_CONTEXT"]
"""

@pytest.mark.compilertest
def test_tracing_config_v3():
aconf = Config()

yaml = module_and_mapping_manifests(None, []) + "\n" + lightstep_tracing_service_manifest()
fetcher = ResourceFetcher(logger, aconf)
fetcher.parse_yaml(yaml, k8s=True)

aconf.load_all(fetcher.sorted())

secret_handler = MockSecretHandler(logger, "mockery", "/tmp/ambassador/snapshots", "v1")
ir = IR(aconf, file_checker=lambda path: True, secret_handler=secret_handler)

assert ir

econf = EnvoyConfig.generate(ir, "V3")

bootstrap_config, ads_config, _ = econf.split_config()
assert "tracing" in bootstrap_config
assert bootstrap_config["tracing"] == {
"http": {
"name": "envoy.lightstep",
"typed_config": {
"@type": "type.googleapis.com/envoy.config.trace.v3.LightstepConfig",
"access_token_file": "/lightstep-credentials/access-token",
"collector_cluster": "cluster_tracing_lightstep_80_ambassador",
"propagation_modes": ["ENVOY", "TRACE_CONTEXT"]
}
}
}

ads_config.pop('@type', None)
assert_valid_envoy_config(ads_config)
assert_valid_envoy_config(bootstrap_config)


@pytest.mark.compilertest
def test_tracing_config_v2():
aconf = Config()

yaml = module_and_mapping_manifests(None, []) + "\n" + lightstep_tracing_service_manifest()
fetcher = ResourceFetcher(logger, aconf)
fetcher.parse_yaml(yaml, k8s=True)

aconf.load_all(fetcher.sorted())

secret_handler = MockSecretHandler(logger, "mockery", "/tmp/ambassador/snapshots", "v1")
ir = IR(aconf, file_checker=lambda path: True, secret_handler=secret_handler)

assert ir

econf = EnvoyConfig.generate(ir, "V2")

bootstrap_config, ads_config, _ = econf.split_config()
assert "tracing" in bootstrap_config
assert bootstrap_config["tracing"] == {
"http": {
"name": "envoy.lightstep",
"typed_config": {
"@type": "type.googleapis.com/envoy.config.trace.v2.LightstepConfig",
"access_token_file": "/lightstep-credentials/access-token",
"collector_cluster": "cluster_tracing_lightstep_80_ambassador",
"propagation_modes": ["ENVOY", "TRACE_CONTEXT"]
}
}
}

ads_config.pop('@type', None)
assert_valid_envoy_config(ads_config, v2=True)
assert_valid_envoy_config(bootstrap_config, v2=True)

0 comments on commit 66c957e

Please sign in to comment.