Skip to content

Commit

Permalink
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
Browse files Browse the repository at this point in the history
…tor into feature_gates_pt2
  • Loading branch information
Aneurysm9 committed Nov 18, 2021
2 parents 063b3a3 + e23c9d0 commit d0faa47
Show file tree
Hide file tree
Showing 86 changed files with 1,950 additions and 1,584 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,41 +152,3 @@ jobs:
file: ./coverage.txt
fail_ci_if_error: true
verbose: true
cross-compile:
runs-on: ubuntu-latest
needs: [setup-environment]
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Setup Go
uses: actions/[email protected]
with:
go-version: 1.17
- name: Setup Go Environment
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Cache Go
id: module-cache
uses: actions/cache@v2
with:
path: /home/runner/go/pkg/mod
key: go-pkg-mod-${{ runner.os }}-${{ hashFiles('**/go.mod', '**/go.sum') }}
- name: Build Collector for All Architectures
run: make binaries-all-sys
- name: Create Collector Binaries Archive
run: tar -cvf bin.tar ./bin
- name: Upload Collector Binaries
uses: actions/[email protected]
with:
name: collector-binaries
path: ./bin.tar
- name: Build Unstable Collector for All Architectures
run: make binaries-all-sys-unstable
- name: Create Unstable Collector Binaries Archive
run: tar -cvf bin-unstable.tar ./bin/*unstable
- name: Upload Unstable Collector Binaries
uses: actions/[email protected]
with:
name: collector-binaries-unstable
path: ./bin-unstable.tar
3 changes: 1 addition & 2 deletions .github/workflows/builder-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Builder - Release
on:
push:
tags:
- 'v*'
- 'cmd/builder/v*'

jobs:
goreleaser:
Expand All @@ -26,7 +26,6 @@ jobs:
distribution: goreleaser-pro
version: latest
args: release --rm-dist
workdir: cmd/builder
env:
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33 changes: 33 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This action requires that any PR targeting the main branch should touch at
# least one CHANGELOG file. If a CHANGELOG entry is not required, add the "Skip
# Changelog" label to disable this action.

name: changelog

on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
jobs:
changelog:
runs-on: ubuntu-latest
if: "!contains(github.event.pull_request.labels.*.name, 'Skip Changelog')"

steps:
- uses: actions/checkout@v2

- name: Check for CHANGELOG changes
run: |
# Only the latest commit of the feature branch is available
# automatically. To diff with the base branch, we need to
# fetch that too (and we only need its latest commit).
git fetch origin ${{ github.base_ref }} --depth=1
if [[ $(git diff --name-only FETCH_HEAD | grep CHANGELOG) ]]
then
echo "A CHANGELOG was modified. Looks good!"
else
echo "No CHANGELOG was modified."
echo "Please add a CHANGELOG entry, or add the \"Skip Changelog\" label if not required."
false
fi
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,40 @@

## 🛑 Breaking changes 🛑

- Remove `pdata.AttributeMap.InitFromMap` (#4429)

## v0.39.0 Beta

## 🛑 Breaking changes 🛑

- Remove deprecated config (already no-op) `ballast_size_mib` in memorylimiterprocessor (#4365)
- Remove `config.Receivers`, `config.Exporters`, `config.Processors`, and `config.Extensions`. Use map directly (#4344)
- Remove `component.BaseProcessorFactory`, use `processorhelper.NewFactory` instead (#4175)
- Force usage of `exporterhelper.NewFactory` to implement `component.ExporterFactory` (#4338)
- Force usage of `receiverhelper.NewFactory` to implement `component.ReceiverFactory` (#4338)
- Force usage of `extensionhelper.NewFactory` to implement `component.ExtensionFactory` (#4338)
- Move `service/parserprovider` package to `config/configmapprovider` (#4206)
- Rename `MapProvider` interface to `Provider`
- Remove `MapProvider` from helper names
- Renamed slice-valued `pdata` types and functions for consistency. (#4325)
- Rename `pdata.AnyValueArray` to `pdata.AttributeValueSlice`
- Rename `ArrayVal()` to `SliceVal()`
- Rename `SetArrayVal()` to `SetSliceVal()`
- Remove `config.Pipeline.Name` (#4326)
- Rename `config.Mapprovider` as `configmapprovider.Provider` (#4337)
- Move `config.WatchableRetrieved` and `config.Retrieved` interfaces to `config/configmapprovider` package (#4337)
- Remove `config.Pipeline.InputDataType` (#4343)
- otlpexporter: Do not retry on PermissionDenied and Unauthenticated (#4349)
- Remove deprecated funcs `consumererror.As[Traces|Metrics|Logs]` (#4364)
- Remove support to expand env variables in default configs (#4366)

## 💡 Enhancements 💡
- Supports more compression methods(`snappy` and `zstd`) for configgrpc, in addition to current `gzip` (#4088)
- Moved the OpenTelemetry Collector Builder to core (#4307)

## 🧰 Bug fixes 🧰

- Fix AggregationTemporality and IsMonotonic when metric descriptors are split in the batch processor (#4389)

## v0.38.0 Beta

Expand Down
93 changes: 8 additions & 85 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ version:
@echo ${VERSION}

.PHONY: all
all: checklicense checkdoc misspell goimpi golint gotest otelcol
all: checklicense checkdoc misspell goimpi golint gotest

all-modules:
@echo $(ALL_MODULES) | tr ' ' '\n' | sort
Expand Down Expand Up @@ -140,26 +140,9 @@ install-tools:
cd $(TOOLS_MOD_DIR) && go install github.com/jcchavezs/porto/cmd/porto
cd $(TOOLS_MOD_DIR) && go install go.opentelemetry.io/build-tools/multimod

.PHONY: otelcol
otelcol:
go generate ./...
$(MAKE) build-binary-internal

.PHONY: otelcol-unstable
otelcol-unstable:
go generate ./...
$(MAKE) build-binary-internal-unstable

.PHONY: run
run:
GO111MODULE=on go run --race ./cmd/otelcol/... --config ${RUN_CONFIG} ${RUN_ARGS}

.PHONY: docker-component # Not intended to be used directly
docker-component: check-component
GOOS=linux $(MAKE) $(COMPONENT)
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT)
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/
rm ./cmd/$(COMPONENT)/$(COMPONENT)
run: build-binary-cmd-otelcol
./bin/cmd-otelcol --config ${RUN_CONFIG} ${RUN_ARGS}

.PHONY: for-all
for-all:
Expand Down Expand Up @@ -207,71 +190,11 @@ delete-tag:
git tag -d "$${dir:2}/$${TAG}" ); \
done

.PHONY: docker-otelcol
docker-otelcol:
COMPONENT=otelcol $(MAKE) docker-component

# build collector binaries with different OS and Architecture
.PHONY: binaries-all-sys
binaries-all-sys: binaries-darwin_amd64 binaries-darwin_arm64 binaries-linux_amd64 binaries-linux_arm64 binaries-windows_amd64

.PHONY: binaries-all-sys-unstable
binaries-all-sys-unstable: binaries-darwin_amd64-unstable binaries-darwin_arm64-unstable binaries-linux_amd64-unstable binaries-linux_arm64-unstable binaries-windows_amd64-unstable

.PHONY: binaries-darwin_amd64
binaries-darwin_amd64:
GOOS=darwin GOARCH=amd64 $(MAKE) build-binary-internal

.PHONY: binaries-darwin_arm64
binaries-darwin_arm64:
GOOS=darwin GOARCH=arm64 $(MAKE) build-binary-internal

.PHONY: binaries-linux_amd64
binaries-linux_amd64:
GOOS=linux GOARCH=amd64 $(MAKE) build-binary-internal

.PHONY: binaries-linux_arm64
binaries-linux_arm64:
GOOS=linux GOARCH=arm64 $(MAKE) build-binary-internal

.PHONY: binaries-windows_amd64
binaries-windows_amd64:
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) build-binary-internal

.PHONY: binaries-darwin_amd64-unstable
binaries-darwin_amd64-unstable:
GOOS=darwin GOARCH=amd64 $(MAKE) build-binary-internal-unstable

.PHONY: binaries-darwin_arm64-unstable
binaries-darwin_arm64-unstable:
GOOS=darwin GOARCH=arm64 $(MAKE) build-binary-internal-unstable

.PHONY: binaries-linux_amd64-unstable
binaries-linux_amd64-unstable:
GOOS=linux GOARCH=amd64 $(MAKE) build-binary-internal-unstable

.PHONY: binaries-linux_arm64-unstable
binaries-linux_arm64-unstable:
GOOS=linux GOARCH=arm64 $(MAKE) build-binary-internal-unstable

.PHONY: binaries-windows_amd64-unstable
binaries-windows_amd64-unstable:
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) build-binary-internal-unstable

.PHONY: build-binary-internal
build-binary-internal:
GO111MODULE=on CGO_ENABLED=0 go build -trimpath -o ./bin/otelcol_$(GOOS)_$(GOARCH)$(EXTENSION) $(BUILD_INFO) ./cmd/otelcol

.PHONY: build-binary-internal-unstable
build-binary-internal-unstable:
GO111MODULE=on CGO_ENABLED=0 go build -trimpath -o ./bin/otelcol_$(GOOS)_$(GOARCH)$(EXTENSION)_unstable $(BUILD_INFO) -tags enable_unstable ./cmd/otelcol

.PHONY: deb-rpm-package
%-package: ARCH ?= amd64
%-package:
$(MAKE) binaries-linux_$(ARCH)
docker build -t otelcol-fpm internal/buildscripts/packaging/fpm
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcol-fpm
# Builds a collector binary of the removed cmd/otelcol directory
.PHONY: build-binary-cmd-otelcol
build-binary-cmd-otelcol:
mkdir -p ./bin
pushd cmd/builder/ && go run ./ --config ../../internal/buildscripts/builder-config.yaml --output-path ../../bin && popd

.PHONY: genmdata
genmdata:
Expand Down
91 changes: 67 additions & 24 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,44 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package client contains generic representations of clients connecting to different receivers
// Package client contains generic representations of clients connecting to
// different receivers. Components, such as processors or exporters, can make
// use of this information to make decisions related to grouping of batches,
// tenancy, load balancing, tagging, among others.
//
// The structs defined here are typically used within the context that is
// propagated down the pipeline, with the values being produced by receivers,
// and consumed by processors and exporters.
//
// Producers
//
// Receivers are responsible for obtaining a client.Info from the current
// context and enhancing the client.Info with the net.Addr from the peer,
// storing a new client.Info into the context that it passes down. For HTTP
// requests, the net.Addr is typically the IP address of the client.
//
// Typically, however, receivers would delegate this processing to helpers such
// as the confighttp or configgrpc packages: both contain interceptors that will
// enhance the context with the client.Info, such that no actions are needed by
// receivers that are built using confighttp.HTTPServerSettings or
// configgrpc.GRPCServerSettings.
//
// Consumers
//
// Provided that the pipeline does not contain processors that would discard or
// rewrite the context, such as the batch processor, processors and exporters
// have access to the client.Info via client.FromContext. Among other usages,
// this data can be used to:
//
// - annotate data points with authentication data (username, tenant, ...)
//
// - route data points based on authentication data
//
// - rate limit client calls based on IP addresses
//
// Processors and exporters relying on the existence of data from the
// client.Info, should clearly document this as part of the component's README
// file.
package client // import "go.opentelemetry.io/collector/client"

import (
Expand All @@ -25,50 +62,56 @@ import (

type ctxKey struct{}

// Client represents a generic client that sends data to any receiver supported by the OT receiver
type Client struct {
IP string
// Info contains data related to the clients connecting to receivers.
type Info struct {
// Addr for the client connecting to this collector. Available in a
// best-effort basis, and generally reliable for receivers making use of
// confighttp.ToServer and configgrpc.ToServerOption.
Addr net.Addr
}

// NewContext takes an existing context and derives a new context with the client value stored on it
func NewContext(ctx context.Context, c *Client) context.Context {
// NewContext takes an existing context and derives a new context with the
// client.Info value stored on it.
func NewContext(ctx context.Context, c Info) context.Context {
return context.WithValue(ctx, ctxKey{}, c)
}

// FromContext takes a context and returns a Client value from it, if present.
func FromContext(ctx context.Context) (*Client, bool) {
c, ok := ctx.Value(ctxKey{}).(*Client)
return c, ok
// FromContext takes a context and returns a ClientInfo from it.
// When a ClientInfo isn't present, a new empty one is returned.
func FromContext(ctx context.Context) Info {
c, ok := ctx.Value(ctxKey{}).(Info)
if !ok {
c = Info{}
}
return c
}

// FromGRPC takes a GRPC context and tries to extract client information from it
func FromGRPC(ctx context.Context) (*Client, bool) {
func FromGRPC(ctx context.Context) (Info, bool) {
if p, ok := peer.FromContext(ctx); ok {
ip := parseIP(p.Addr.String())
if ip != "" {
return &Client{ip}, true
if ip != nil {
return Info{ip}, true
}
}
return nil, false
return Info{}, false
}

// FromHTTP takes a net/http Request object and tries to extract client information from it
func FromHTTP(r *http.Request) (*Client, bool) {
func FromHTTP(r *http.Request) (Info, bool) {
ip := parseIP(r.RemoteAddr)
if ip == "" {
return nil, false
if ip == nil {
return Info{}, false
}
return &Client{ip}, true
return Info{ip}, true
}

func parseIP(source string) string {
func parseIP(source string) net.Addr {
ipstr, _, err := net.SplitHostPort(source)
if err == nil {
return ipstr
source = ipstr
}
ip := net.ParseIP(source)
if ip != nil {
return ip.String()
return &net.IPAddr{
IP: net.ParseIP(source),
}
return ""
}
Loading

0 comments on commit d0faa47

Please sign in to comment.