Skip to content

Commit

Permalink
NH-86973 - OTelcol: Telemetry API 403 and Unable to getSettings from …
Browse files Browse the repository at this point in the history
…solarwindsapmsettingsextension (#39)

* Synced with upstream
* Fixed telemetry API 403 by maintaining the correct order of initialization
* Added system cert pool to gRPC TLS config
  • Loading branch information
jerrytfleung authored Jul 24, 2024
1 parent 474cf18 commit 3a224f0
Show file tree
Hide file tree
Showing 38 changed files with 1,255 additions and 1,483 deletions.
4 changes: 4 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ changelog:
labels:
- java

- title: Ruby
labels:
- ruby

- title: Other Dependencies
labels:
- dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-layer-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
- us-west-1
- us-west-2
with:
artifact-name: opentelemetry-javawrapper-layer.zip
artifact-name: opentelemetry-java-wrapper.zip
layer-name: opentelemetry-javawrapper
component-version: "--"
# architecture:
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/release-layer-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ jobs:
- uses: actions/checkout@v4

- name: Build
id: save-ruby-sdk-version
run: |
./build.sh
shell: bash
working-directory: ruby/src

- name: Save Ruby SDK Version
id: save-ruby-sdk-version
run: |
unzip -q build/opentelemetry-ruby-layer.zip
export GEM_PATH=$PWD/ruby/gems/3.2.0/
RUBY_SDK_VERSION=$(ruby -e 'require "opentelemetry-sdk"; puts OpenTelemetry::SDK::VERSION')
echo "RUBY_SDK_VERSION=$RUBY_SDK_VERSION" >> $GITHUB_OUTPUT
working-directory: ruby/src

- name: Show directory contents
run: |
ls -al
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ __pycache__/*
build.toml

*.zip

collector/VERSION
58 changes: 58 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# OpenTelemetry Contributor Guide

Welcome to OpenTelemetry! This document provides general guidance for contributing to
this codebase. This is a multi-lingual codebase, so sub-directories like `collector` may
provide additional guidance in a CONTRIBUTING.md.
contribute to the code base. Feel free to browse the [open
issues](https://github.com/open-telemetry/opentelemetry-lambda/issues?q=is%3Aissue+is%3Aopen)
and file new ones, all feedback welcome!

## Before you get started

### Code of Conduct

Please make sure to read and observe our [Code of
Conduct](https://github.com/open-telemetry/community/blob/master/code-of-conduct.md).

### Sign the CLA

Before you can contribute, you will need to sign the [Contributor License
Agreement](https://docs.linuxfoundation.org/lfx/easycla/contributors).

### Code attribution

[License information](README.md#License) should be included in all source files where applicable.
Either full or short version of the header should be used as described at [apache.org](http://www.apache.org/foundation/license-faq.html#Apply-My-Software).
It is OK to exclude the year from the copyright notice. For the details on how to apply the copyright,
see the next section.

### Copyright Notices

OpenTelemetry follows [CNCF recommendations](https://github.com/cncf/foundation/blob/master/copyright-notices.md)
for copyright notices. We use "Copyright The OpenTelemetry Authors" notice form.

According to CNCF recommendations if you are contributing third-party code
you will need to [retain the original copyright notice](https://github.com/cncf/foundation/blob/master/copyright-notices.md#dont-change-someone-elses-notice-without-their-permission).

Any contributed third-party code must originally be Apache 2.0-Licensed or must
carry a permisive software license that is compatible when combining with
Apache 2.0 License. At this moment, BSD and MIT are the only
[OSI-approved licenses](https://opensource.org/licenses/alphabetical) known to be compatible.

If you make substantial changes to the third-party code, _prepend_ the contributed
third party file with OpenTelemetry's copyright notice.

If the contributed code is not third-party code and you are the author we
strongly encourage to avoid including your name in the notice and use the
generic "Copyright The OpenTelemetry Authors" notice. See rationale for this
recommendation [here](https://github.com/cncf/foundation/blob/master/copyright-notices.md#why-not-list-every-copyright-holder).

## Community Expectations and Roles

OpenTelemetry is a community project. Consequently, it is wholly dependent on
its community to provide a productive, friendly, and collaborative environment.

- See [Community
Membership](https://github.com/open-telemetry/community/blob/master/community-membership.md)
for a list the various responsibilities of contributor roles. You are
encouraged to move up this contributor ladder as you gain experience.
12 changes: 8 additions & 4 deletions collector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ BASE_SPACE:=$(shell pwd)
BUILD_SPACE:=$(BASE_SPACE)/build
BUCKET_NAME:=lambda-artifacts-$(shell dd if=/dev/random bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d ' \t\n')
LAYER_NAME:=otel-collector

VERSION=$(shell cat VERSION)
OTELCOL_VERSION=$(shell cat VERSION)
GIT_SHA=$(shell git rev-parse HEAD)
GOARCH ?= amd64

Expand All @@ -18,7 +17,7 @@ endif
GOBUILD=GO111MODULE=on CGO_ENABLED=0 installsuffix=cgo go build -trimpath
BUILD_INFO_IMPORT_PATH=main

LDFLAGS=-ldflags "-s -w -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) -X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION) \
LDFLAGS=-ldflags "-s -w -X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) -X $(BUILD_INFO_IMPORT_PATH).Version=$(OTELCOL_VERSION) \
-X github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter.collectorDistribution=opentelemetry-collector-lambda"

TOOLS_MOD_DIR := ./internal/tools
Expand All @@ -41,7 +40,7 @@ clean:
rm -rf build/

.PHONY: build
build: clean
build: clean set-otelcol-version
@echo Building otel collector extension
mkdir -p $(BUILD_SPACE)/extensions
GOOS=linux GOARCH=$(GOARCH) $(GOBUILD) $(LDFLAGS) -o $(BUILD_SPACE)/extensions .
Expand All @@ -63,6 +62,11 @@ publish-layer: package
aws lambda publish-layer-version --layer-name $(LAYER_NAME) --zip-file fileb://$(BUILD_SPACE)/opentelemetry-collector-layer-$(ARCH).zip --compatible-runtimes nodejs14.x nodejs16.x nodejs18.x java11 python3.8 python3.9 python3.10 python3.11 --compatible-architectures $(ARCH) --query 'LayerVersionArn' --output text
@echo OpenTelemetry Collector layer published.

.PHONY: set-otelcol-version
set-otelcol-version:
@OTELCOL_VERSION=$$(grep "go.opentelemetry.io/collector/otelcol v" go.mod | awk '{print $$2; exit}'); \
echo $$OTELCOL_VERSION > VERSION; \

.PHONY: gotidy
gotidy:
@$(MAKE) for-all-target TARGET="tidy"
Expand Down
1 change: 0 additions & 1 deletion collector/VERSION

This file was deleted.

33 changes: 21 additions & 12 deletions collector/extension/solarwindsapmsettingsextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package solarwindsapmsettingsextension
import (
"context"
"crypto/tls"
"crypto/x509"
"encoding/binary"
"encoding/json"
"github.com/solarwindscloud/apm-proto/go/collectorpb"
Expand All @@ -19,8 +20,8 @@ import (
)

const (
JSONOutputFile = "/tmp/solarwinds-apm-settings.json"
GrpcContextDeadline = time.Duration(1) * time.Second
jsonOutputFile = "/tmp/solarwinds-apm-settings.json"
grpcContextDeadline = 1 * time.Second
)

type solarwindsapmSettingsExtension struct {
Expand All @@ -44,7 +45,7 @@ func refresh(extension *solarwindsapmSettingsExtension) {
if hostname, err := os.Hostname(); err != nil {
extension.logger.Error("Unable to call os.Hostname() " + err.Error())
} else {
ctx, cancel := context.WithTimeout(context.Background(), GrpcContextDeadline)
ctx, cancel := context.WithTimeout(context.Background(), grpcContextDeadline)
defer cancel()

request := &collectorpb.SettingsRequest{
Expand Down Expand Up @@ -143,13 +144,13 @@ func refresh(extension *solarwindsapmSettingsExtension) {
if content, err := json.Marshal(settings); err != nil {
extension.logger.Warn("Error to marshal setting JSON[] byte from settings " + err.Error())
} else {
if err := os.WriteFile(JSONOutputFile, content, 0644); err != nil {
extension.logger.Error("Unable to write " + JSONOutputFile + " " + err.Error())
if err := os.WriteFile(jsonOutputFile, content, 0644); err != nil {
extension.logger.Error("Unable to write " + jsonOutputFile + " " + err.Error())
} else {
if len(response.GetWarning()) > 0 {
extension.logger.Warn(JSONOutputFile + " is refreshed (soft disabled)")
extension.logger.Warn(jsonOutputFile + " is refreshed (soft disabled)")
} else {
extension.logger.Info(JSONOutputFile + " is refreshed")
extension.logger.Info(jsonOutputFile + " is refreshed")
}
extension.logger.Info(string(content))
}
Expand All @@ -169,16 +170,24 @@ func refresh(extension *solarwindsapmSettingsExtension) {
}
}

func (extension *solarwindsapmSettingsExtension) Start(ctx context.Context, _ component.Host) error {
func (extension *solarwindsapmSettingsExtension) Start(_ context.Context, _ component.Host) error {
extension.logger.Info("Starting up solarwinds apm settings extension")
ctx = context.Background()
ctx := context.Background()
ctx, extension.cancel = context.WithCancel(ctx)
var err error
extension.conn, err = grpc.Dial(extension.config.Endpoint, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})))
systemCertPool, err := x509.SystemCertPool()
if err != nil {
extension.logger.Error("Getting system cert pool failed: ", zap.Error(err))
return err
}
extension.logger.Info("grpc.Dail to " + extension.config.Endpoint)
extension.logger.Info("Got system cert pool")
subjects := systemCertPool.Subjects()
extension.logger.Info("Loaded system certificates", zap.Int("numberOfCertificates", len(subjects)))
extension.conn, err = grpc.NewClient(extension.config.Endpoint, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{RootCAs: systemCertPool})))
if err != nil {
extension.logger.Error("grpc.NewClient creation failed: ", zap.Error(err))
return err
}
extension.logger.Info("Created a grpc.NewClient", zap.String("endpoint", extension.config.Endpoint))
extension.client = collectorpb.NewTraceCollectorClient(extension.conn)

// initial refresh
Expand Down
44 changes: 22 additions & 22 deletions collector/extension/solarwindsapmsettingsextension/go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module github.com/open-telemetry/opentelemetry-lambda/collector/extension/solarwindsapmsettingsextension

go 1.21
go 1.21.0

toolchain go1.22.2
toolchain go1.22.5

require (
github.com/solarwindscloud/apm-proto v1.0.3
github.com/solarwindscloud/apm-proto v1.0.5
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/component v0.99.0
go.opentelemetry.io/collector/confmap v0.99.0
go.opentelemetry.io/collector/extension v0.99.0
go.opentelemetry.io/otel/metric v1.25.0
go.opentelemetry.io/otel/trace v1.25.0
go.opentelemetry.io/collector/component v0.102.1
go.opentelemetry.io/collector/confmap v0.102.1
go.opentelemetry.io/collector/extension v0.102.1
go.opentelemetry.io/otel/metric v1.27.0
go.opentelemetry.io/otel/trace v1.27.0
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -32,20 +32,20 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.52.3 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.99.0 // indirect
go.opentelemetry.io/collector/pdata v1.6.0 // indirect
go.opentelemetry.io/otel v1.25.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.47.0 // indirect
go.opentelemetry.io/otel/sdk v1.25.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.25.0 // indirect
github.com/prometheus/common v0.53.0 // indirect
github.com/prometheus/procfs v0.15.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.102.1 // indirect
go.opentelemetry.io/collector/pdata v1.9.0 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.49.0 // indirect
go.opentelemetry.io/otel/sdk v1.27.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.27.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 3a224f0

Please sign in to comment.