Skip to content

Commit

Permalink
Option to export traces to GCP (#479)
Browse files Browse the repository at this point in the history
* Option to export traces to GCP

* fix
  • Loading branch information
DanG100 committed Sep 24, 2024
1 parent efc1b32 commit a008805
Show file tree
Hide file tree
Showing 8 changed files with 533 additions and 318 deletions.
30 changes: 30 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ http_archive(
],
)

http_archive(
name = "rules_distroless",
sha256 = "44c1e485723ad342212b48e410bae50306b5f8b39da65243e1db2f5b74faa8d6",
strip_prefix = "rules_distroless-0.3.7",
url = "https://github.com/GoogleContainerTools/rules_distroless/releases/download/v0.3.7/rules_distroless-v0.3.7.tar.gz",
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
Expand Down Expand Up @@ -114,6 +121,29 @@ switched_rules_by_language(
grpc = True,
)

# Distroless

load("@rules_distroless//distroless:dependencies.bzl", "distroless_dependencies")

distroless_dependencies()

load("@rules_distroless//distroless:toolchains.bzl", "distroless_register_toolchains")

distroless_register_toolchains()

load("@rules_distroless//apt:index.bzl", "deb_index")

# bazel run @bookworm//:lock
deb_index(
name = "bookworm",
lock = "//:bookworm.lock.json",
manifest = "//:bookworm.yaml",
)

load("@bookworm//:packages.bzl", "bookworm_packages")

bookworm_packages()

# OCI Container

load("@rules_oci//oci:dependencies.bzl", "rules_oci_dependencies")
Expand Down
85 changes: 85 additions & 0 deletions bookworm.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"packages": [
{
"arch": "amd64",
"dependencies": [
{
"key": "openssl_3.0.14-1_deb12u2_amd64",
"name": "openssl",
"version": "3.0.14-1~deb12u2"
},
{
"key": "libssl3_3.0.14-1_deb12u2_amd64",
"name": "libssl3",
"version": "3.0.14-1~deb12u2"
},
{
"key": "libc6_2.36-9-p-deb12u8_amd64",
"name": "libc6",
"version": "2.36-9+deb12u8"
},
{
"key": "libgcc-s1_12.2.0-14_amd64",
"name": "libgcc-s1",
"version": "12.2.0-14"
},
{
"key": "gcc-12-base_12.2.0-14_amd64",
"name": "gcc-12-base",
"version": "12.2.0-14"
}
],
"key": "ca-certificates_20230311_amd64",
"name": "ca-certificates",
"sha256": "5308b9bd88eebe2a48be3168cb3d87677aaec5da9c63ad0cf561a29b8219115c",
"url": "https://snapshot.debian.org/archive/debian/20240917T144520Z/pool/main/c/ca-certificates/ca-certificates_20230311_all.deb",
"version": "20230311"
},
{
"arch": "amd64",
"dependencies": [],
"key": "openssl_3.0.14-1_deb12u2_amd64",
"name": "openssl",
"sha256": "0bd921ff96a15479fcd98f47d418718bb0b92ae6a94cd93eccdf127899e8af6f",
"url": "https://snapshot.debian.org/archive/debian-security/20240917T144520Z/pool/updates/main/o/openssl/openssl_3.0.14-1~deb12u2_amd64.deb",
"version": "3.0.14-1~deb12u2"
},
{
"arch": "amd64",
"dependencies": [],
"key": "libssl3_3.0.14-1_deb12u2_amd64",
"name": "libssl3",
"sha256": "b308a8fd9889fd7e57b801511e3f42a203675b6b0087455a977d25b7633a1296",
"url": "https://snapshot.debian.org/archive/debian-security/20240917T144520Z/pool/updates/main/o/openssl/libssl3_3.0.14-1~deb12u2_amd64.deb",
"version": "3.0.14-1~deb12u2"
},
{
"arch": "amd64",
"dependencies": [],
"key": "libc6_2.36-9-p-deb12u8_amd64",
"name": "libc6",
"sha256": "dbb527d86181f4b50edf5790c34c4d0b4ceac7f199b1266a9336b5708f8e9798",
"url": "https://snapshot.debian.org/archive/debian/20240917T144520Z/pool/main/g/glibc/libc6_2.36-9+deb12u8_amd64.deb",
"version": "2.36-9+deb12u8"
},
{
"arch": "amd64",
"dependencies": [],
"key": "libgcc-s1_12.2.0-14_amd64",
"name": "libgcc-s1",
"sha256": "f3d1d48c0599aea85b7f2077a01d285badc42998c1a1e7473935d5cf995c8141",
"url": "https://snapshot.debian.org/archive/debian/20240917T144520Z/pool/main/g/gcc-12/libgcc-s1_12.2.0-14_amd64.deb",
"version": "12.2.0-14"
},
{
"arch": "amd64",
"dependencies": [],
"key": "gcc-12-base_12.2.0-14_amd64",
"name": "gcc-12-base",
"sha256": "1a03df5a57833d65b5bb08cfa19d50e76f29088dc9e64fb934af42d9023a0807",
"url": "https://snapshot.debian.org/archive/debian/20240917T144520Z/pool/main/g/gcc-12/gcc-12-base_12.2.0-14_amd64.deb",
"version": "12.2.0-14"
}
],
"version": 1
}
13 changes: 13 additions & 0 deletions bookworm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 1

sources:
- channel: bookworm main
url: https://snapshot.debian.org/archive/debian/20240917T144520Z/
- channel: bookworm-security main
url: https://snapshot.debian.org/archive/debian-security/20240917T144520Z/

archs:
- "amd64"

packages:
- "ca-certificates"
14 changes: 13 additions & 1 deletion dataplane/standalone/lucius/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@rules_distroless//distroless:defs.bzl", "cacerts")
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_tarball")
load("@rules_pkg//:pkg.bzl", "pkg_tar")

Expand All @@ -12,6 +13,7 @@ go_library(
"//dataplane/saiserver",
"//dataplane/saiserver/attrmgr",
"//proto/forwarding",
"@com_github_googlecloudplatform_opentelemetry_operations_go_exporter_trace//:trace",
"@com_github_grpc_ecosystem_go_grpc_middleware_v2//interceptors/logging",
"@io_opentelemetry_go_contrib_instrumentation_google_golang_org_grpc_otelgrpc//:otelgrpc",
"@io_opentelemetry_go_otel//:otel",
Expand Down Expand Up @@ -41,11 +43,21 @@ pkg_tar(
package_dir = "lucius",
)

cacerts(
name = "cacerts",
package = select({
"@platforms//cpu:x86_64": "@bookworm//ca-certificates/amd64:data",
}),
)

oci_image(
name = "image",
base = "@debian_bookworm",
entrypoint = ["/lucius/lucius"],
tars = [":bin-tar"],
tars = [
":bin-tar",
":cacerts",
],
)

# Note: This is image isn't suitable for release, as it doesn't contain license information.
Expand Down
25 changes: 19 additions & 6 deletions dataplane/standalone/lucius/lucius.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"log/slog"
"net"

texporter "github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
Expand All @@ -48,11 +49,13 @@ import (
var (
port = flag.Int("port", 50000, "Port for api server")
// All below flags are not used, kept for now to prevent breaking exsting users, will be removed in future release.
_ = flag.String("config_file", "", "Path to config file (deprecated, no-op will always to true in future release)")
_ = flag.String("port_map", "", "Map of modeled port names to Linux interface to as comma seperated list (eg Ethernet8:eth1,Ethernet10,eth2) (deprecated, no-op will be removed in future release)")
_ = flag.Bool("eth_dev_as_lane", true, "If true, when creating ports, use ethX and hardware lane X (deprecated, no-op will always to true in future release)")
_ = flag.Bool("remote_cpu_port", true, "If true, send all packets from/to the CPU port over gRPC (deprecated, no-op will always to true in future release)")
hwProfile = flag.String("hw_profile", "", "Path to hardware profile config file.")
_ = flag.String("config_file", "", "Path to config file (deprecated, no-op will always to true in future release)")
_ = flag.String("port_map", "", "Map of modeled port names to Linux interface to as comma seperated list (eg Ethernet8:eth1,Ethernet10,eth2) (deprecated, no-op will be removed in future release)")
_ = flag.Bool("eth_dev_as_lane", true, "If true, when creating ports, use ethX and hardware lane X (deprecated, no-op will always to true in future release)")
_ = flag.Bool("remote_cpu_port", true, "If true, send all packets from/to the CPU port over gRPC (deprecated, no-op will always to true in future release)")
gcpTelemExport = flag.Bool("gcp_telem_export", false, "If true, export OTEL telemetry to GCP")
gcpProject = flag.String("gcp_project", "", "GCP project to export to, by default it will use project where the GCE instance is running")
hwProfile = flag.String("hw_profile", "", "Path to hardware profile config file.")
)

func main() {
Expand Down Expand Up @@ -119,6 +122,16 @@ func start(port int) {
func setupOTelSDK(ctx context.Context) (func(context.Context) error, error) {
var shutdownFuncs []func(context.Context) error

var exporter sdktrace.SpanExporter

var err error
if *gcpTelemExport {
exporter, err = texporter.New(texporter.WithProjectID(*gcpProject))
if err != nil {
return nil, err
}
}

shutdown := func(ctx context.Context) error {
var err error
for _, fn := range shutdownFuncs {
Expand All @@ -134,7 +147,7 @@ func setupOTelSDK(ctx context.Context) (func(context.Context) error, error) {
prop := newPropagator()
otel.SetTextMapPropagator(prop)

bsp := sdktrace.NewBatchSpanProcessor(nil)
bsp := sdktrace.NewBatchSpanProcessor(exporter)
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
sdktrace.WithResource(res),
Expand Down
41 changes: 23 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ go 1.22
toolchain go1.22.3

require (
cloud.google.com/go/cloudbuild v1.15.1
cloud.google.com/go/cloudbuild v1.16.3
github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/trace v1.24.1
github.com/fatih/color v1.15.0
github.com/go-logr/logr v1.4.2
github.com/golang/glog v1.2.1
Expand Down Expand Up @@ -38,7 +39,7 @@ require (
github.com/spf13/viper v1.19.0
github.com/stoewer/go-strcase v1.3.0
github.com/vishvananda/netlink v1.2.1-beta.2
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0
go.opentelemetry.io/otel v1.30.0
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.6.0
go.opentelemetry.io/otel/log v0.6.0
Expand All @@ -47,11 +48,12 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.27.0
go.opentelemetry.io/otel/trace v1.30.0
go.uber.org/mock v0.2.0
golang.org/x/oauth2 v0.21.0
golang.org/x/sys v0.25.0
google.golang.org/api v0.171.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117
google.golang.org/api v0.188.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5
google.golang.org/grpc v1.64.1
google.golang.org/protobuf v1.34.1
google.golang.org/protobuf v1.34.2
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.29.3
k8s.io/client-go v0.29.3
Expand All @@ -62,11 +64,15 @@ require (

require (
bitbucket.org/creachadair/stringset v0.0.14 // indirect
cloud.google.com/go v0.112.1 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
cloud.google.com/go/pubsub v1.36.1 // indirect
cloud.google.com/go v0.115.0 // indirect
cloud.google.com/go/auth v0.7.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.5.0 // indirect
cloud.google.com/go/iam v1.1.10 // indirect
cloud.google.com/go/longrunning v0.5.9 // indirect
cloud.google.com/go/pubsub v1.40.0 // indirect
cloud.google.com/go/trace v1.10.10 // indirect
github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.48.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/aristanetworks/arista-ceoslab-operator/v2 v2.1.2 // indirect
github.com/carlmontanari/difflibgo v0.0.0-20210718194309-31b9e131c298 // indirect
Expand All @@ -93,7 +99,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
Expand Down Expand Up @@ -141,20 +147,19 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto v0.0.0-20240708141625-4ad9e859172b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240709173604-40e1e62336c5 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit a008805

Please sign in to comment.