Skip to content

Commit

Permalink
Merge branch 'update_dep' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrytfleung authored Jul 22, 2024
2 parents 3869f3a + 5032a83 commit 0eeffc8
Show file tree
Hide file tree
Showing 44 changed files with 2,848 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/layer-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:

- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.PROD_LAMBDA_ROLE_ARN }}
role-to-assume: ${{ inputs.release-group == 'prod' && secrets.PROD_LAMBDA_ROLE_ARN || secrets.STAGING_LAMBDA_ROLE_ARN }}
role-duration-seconds: 1200
aws-region: ${{ inputs.aws_region }}
mask-aws-account-id: false
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/release-layer-collector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
architecture:
- amd64
- x86_64
- arm64
outputs:
COLLECTOR_VERSION: ${{ steps.save-collector-version.outputs.COLLECTOR_VERSION }}
Expand All @@ -25,14 +25,20 @@ jobs:
- uses: actions/setup-go@v5
with:
go-version: '^1.21.9'
- name: set version to the default config.yaml
run: |
version=$(echo ${{ github.ref_name }} | awk -F'/' {'print $2'})
sed -i "s/0.0.0-dev/$version/g" collector/config.yaml
- name: cat collector/config.yaml
run: cat collector/config.yaml
- name: build
run: make -C collector package GOARCH=${{ matrix.architecture }}
run: make -C collector package GOARCH=${{ matrix.architecture == 'x86_64' && 'amd64' || 'arm64' }}
- uses: actions/upload-artifact@v4
with:
name: opentelemetry-collector-layer-${{ matrix.architecture }}.zip
path: ${{ github.workspace }}/collector/build/opentelemetry-collector-layer-${{ matrix.architecture }}.zip
- name: Save Collector Version
if: ${{ matrix.architecture == 'amd64' }}
if: ${{ matrix.architecture == 'x86_64' }}
id: save-collector-version
shell: bash
# `./collector -v` output is in the form `v0.75.0`
Expand All @@ -46,7 +52,7 @@ jobs:
strategy:
matrix:
architecture:
- amd64
- x86_64
- arm64
aws_region:
- ap-northeast-1
Expand Down
81 changes: 81 additions & 0 deletions .github/workflows/release-layer-staging-collector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: "Release Staging Collector Lambda layer"

on:
# (Using tag push instead of release to allow filtering by tag prefix.)
push:
tags:
- layer-staging-collector/**

permissions:
id-token: write
contents: read

jobs:
build-layer:
runs-on: ubuntu-latest
strategy:
matrix:
architecture:
- x86_64
- arm64
outputs:
COLLECTOR_VERSION: ${{ steps.save-collector-version.outputs.COLLECTOR_VERSION }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '^1.21.9'
- name: set version to the default config.yaml
run: |
version=$(echo ${{ github.ref_name }} | awk -F'/' {'print $2'})
sed -i "s/0.0.0-dev/$version/g" collector/config.yaml
- name: cat collector/config.yaml
run: cat collector/config.yaml
- name: build
run: make -C collector package GOARCH=${{ matrix.architecture == 'x86_64' && 'amd64' || 'arm64' }}
- uses: actions/upload-artifact@v4
with:
name: opentelemetry-collector-layer-${{ matrix.architecture }}.zip
path: ${{ github.workspace }}/collector/build/opentelemetry-collector-layer-${{ matrix.architecture }}.zip
- name: Save Collector Version
if: ${{ matrix.architecture == 'x86_64' }}
id: save-collector-version
shell: bash
# `./collector -v` output is in the form `v0.75.0`
run: |
COLLECTOR_VERSION=$( ${{ github.workspace }}/collector/build/extensions/collector -v)
echo "COLLECTOR_VERSION=$COLLECTOR_VERSION" >> $GITHUB_OUTPUT
publish-layer:
uses: ./.github/workflows/layer-publish.yml
needs: build-layer
strategy:
matrix:
architecture:
- x86_64
- arm64
aws_region:
- ap-northeast-1
- ap-northeast-2
- ap-south-1
- ap-southeast-1
- ap-southeast-2
- ca-central-1
- eu-central-1
- eu-north-1
- eu-west-1
- eu-west-2
- eu-west-3
- sa-east-1
- us-east-1
- us-east-2
- us-west-1
- us-west-2
with:
artifact-name: opentelemetry-collector-layer-${{ matrix.architecture }}.zip
layer-name: opentelemetry-collector
component-version: ${{needs.build-layer.outputs.COLLECTOR_VERSION}}
architecture: ${{ matrix.architecture }}
release-group: staging
aws_region: ${{ matrix.aws_region }}
secrets: inherit
13 changes: 10 additions & 3 deletions collector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ LAYER_NAME:=otel-collector
OTELCOL_VERSION="UNSET" # run recipe set-otelcol-version to get this
GIT_SHA=$(shell git rev-parse HEAD)
GOARCH ?= amd64

ifeq ($(GOARCH), amd64)
ARCH=x86_64
else
ARCH=$(GOARCH)
endif

GOBUILD=GO111MODULE=on CGO_ENABLED=0 installsuffix=cgo go build -trimpath
BUILD_INFO_IMPORT_PATH=main

Expand Down Expand Up @@ -43,16 +50,16 @@ package: build
@echo Package zip file for collector extension layer
mkdir -p $(BUILD_SPACE)/collector-config
cp config* $(BUILD_SPACE)/collector-config
cd $(BUILD_SPACE) && zip -r opentelemetry-collector-layer-$(GOARCH).zip collector-config extensions
cd $(BUILD_SPACE) && zip -r opentelemetry-collector-layer-$(ARCH).zip collector-config extensions

.PHONY: publish
publish:
aws lambda publish-layer-version --layer-name $(LAYER_NAME) --zip-file fileb://$(BUILD_SPACE)/opentelemetry-collector-layer-$(GOARCH).zip --compatible-runtimes nodejs14.x nodejs16.x nodejs18.x java11 python3.8 python3.9 python3.10 python3.11 --query 'LayerVersionArn' --output text
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

.PHONY: publish-layer
publish-layer: package
@echo Publishing collector extension layer...
aws lambda publish-layer-version --layer-name $(LAYER_NAME) --zip-file fileb://$(BUILD_SPACE)/opentelemetry-collector-layer-$(GOARCH).zip --compatible-runtimes nodejs14.x nodejs16.x nodejs18.x java11 python3.8 python3.9 python3.10 python3.11 --query 'LayerVersionArn' --output text
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
Expand Down
42 changes: 39 additions & 3 deletions collector/config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,59 @@
extensions:
solarwindsapmsettings:
endpoint: "apm.collector.${SW_APM_DATA_CENTER}.cloud.solarwinds.com:443"
key: "${SW_APM_API_TOKEN}:${OTEL_SERVICE_NAME}"

receivers:
otlp:
protocols:
grpc:
endpoint: "localhost:4317"
http:
endpoint: "localhost:4318"
telemetryapi:
types: ${SW_APM_TELEMETRY_API_SUBSCRIPTION}

processors:
decouple:
resourcedetection:
detectors: [env, system, lambda]
timeout: 0.2s
override: false
resource:
attributes:
- key: sw.cloud.aws.resource.type
value: "Lambda"
action: upsert
- key: sw.apm.otelcol.version
value: "0.0.0-dev"
action: upsert
- key: sw.data.module
value: "apm"
action: upsert

exporters:
logging:
loglevel: debug
verbosity: detailed
otlp:
endpoint: "https://otel.collector.${SW_APM_DATA_CENTER}.cloud.solarwinds.com:443"
headers:
Authorization: "Bearer ${SW_APM_API_TOKEN}"

service:
extensions: [solarwindsapmsettings]
pipelines:
traces:
receivers: [otlp]
exporters: [logging]
processors: [resource,resourcedetection,decouple]
exporters: [otlp,logging]
metrics:
receivers: [otlp]
exporters: [logging]
processors: [resource,resourcedetection,decouple]
exporters: [otlp,logging]
logs:
receivers: [otlp,telemetryapi]
processors: [resource,resourcedetection,decouple]
exporters: [otlp,logging]
telemetry:
metrics:
address: localhost:8888
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
44 changes: 44 additions & 0 deletions collector/extension/solarwindsapmsettingsextension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Solarwinds APM Settings extension

<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [development] |
| Distributions | [] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fsolarwindsapmsettings%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fsolarwindsapmsettings) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fsolarwindsapmsettings%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fsolarwindsapmsettings) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@jerrytfleung](https://www.github.com/jerrytfleung), [@cheempz](https://www.github.com/cheempz) |

[development]: https://github.com/open-telemetry/opentelemetry-collector#development
<!-- end autogenerated section -->

## Overview
The Solarwinds APM Settings extension gets Solarwinds APM specific settings from Solarwinds APM collector and `/tmp/solarwinds-apm-settings.json` periodically.

## Configuration

Example:

```yaml
extensions:
solarwindsapmsettings:
endpoint: "<endpoint>"
key: "<token>:<name>"
interval: 10s
```
### endpoint (Required)
The APM collector endpoint which this extension calls `getSettings`. See [here](https://documentation.solarwinds.com/en/success_center/observability/content/system_requirements/endpoints.htm) for our APM collector endpoints. The endpoint is in format `<host>:<port>`.

### key (Required)
The service key in format `<token>:<name>` for `getSettings` from Solarwinds APM collector. See [here](https://documentation.solarwinds.com/en/success_center/observability/content/configure/configure-services.htm) for configuring a service key.

### interval (Optional)
Periodic interval to get Solarwinds APM specific settings from Solarwinds APM collector.

Minimum value: `5s`

Maximum value: `60s`

Value that is outside the boundary will be bounded to either the minimum or maximum value.

Default: `10s`
67 changes: 67 additions & 0 deletions collector/extension/solarwindsapmsettingsextension/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package solarwindsapmsettingsextension

import (
"os"
"regexp"
"strings"
"time"

"go.opentelemetry.io/collector/component"
)

type Config struct {
Endpoint string `mapstructure:"endpoint"`
Key string `mapstructure:"key"`
Interval time.Duration `mapstructure:"interval"`
}

const (
DefaultEndpoint = "apm.collector.na-01.cloud.solarwinds.com:443"
DefaultInterval = time.Duration(10) * time.Second
MinimumInterval = time.Duration(5) * time.Second
MaximumInterval = time.Duration(60) * time.Second
)

func createDefaultConfig() component.Config {
return &Config{
Endpoint: DefaultEndpoint,
Interval: DefaultInterval,
}
}

func (cfg *Config) Validate() error {
// Endpoint
matched, _ := regexp.MatchString(`apm.collector.[a-z]{2,3}-[0-9]{2}.[a-z\-]*.solarwinds.com:443`, cfg.Endpoint)
if !matched {
// Replaced by the default
cfg.Endpoint = DefaultEndpoint
}
// Key
keyArr := strings.Split(cfg.Key, ":")
if len(keyArr) == 2 && len(keyArr[1]) == 0 {
/**
* Service name is empty. We are trying our best effort to resolve the service name
*/
serviceName := resolveServiceNameBestEffort()
if len(serviceName) > 0 {
cfg.Key = keyArr[0] + ":" + serviceName
}
}
// Interval
if cfg.Interval.Seconds() < MinimumInterval.Seconds() {
cfg.Interval = MinimumInterval
}
if cfg.Interval.Seconds() > MaximumInterval.Seconds() {
cfg.Interval = MaximumInterval
}
return nil
}

func resolveServiceNameBestEffort() string {
if name, ok := os.LookupEnv("OTEL_SERVICE_NAME"); ok && len(name) > 0 {
return name
} else if name, ok := os.LookupEnv("AWS_LAMBDA_FUNCTION_NAME"); ok && len(name) > 0 {
return name
}
return ""
}
Loading

0 comments on commit 0eeffc8

Please sign in to comment.