Skip to content

Commit

Permalink
Kbauer/use dockerized ocb (#163)
Browse files Browse the repository at this point in the history
- migrate to docker-based ocb
- upgrade to 0.112.0 ocb and components
- make build targets lazy
  • Loading branch information
kb-newrelic authored Dec 11, 2024
1 parent 394fd45 commit e11d2bd
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 197 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ TO_DIR=dirname {} \; | sort | grep -E '^./'

ALL_DISTRIBUTIONS := $(shell find ./distributions/* $(FIND_MOD_ARGS) -exec $(TO_DIR) )

# Define a delegation target for each distribution
.PHONY: $(ALL_DISTRIBUTIONS)
$(ALL_DISTRIBUTIONS):
$(MAKE) -C $@ $(TARGET)

# trigger target for each module's delegation target
.PHONY: for-all-target
for-all-target: $(ALL_DISTRIBUTIONS)

include build.mk
include check.mk

Expand Down
64 changes: 48 additions & 16 deletions Makefile.common
Original file line number Diff line number Diff line change
@@ -1,31 +1,63 @@
#############################################
#### Common Makefiles for distributions #####
#############################################
# Note: file is included in Makefile within distro folders,
# so paths are relative to distro folder unless they use SRC_ROOT

# SRC_ROOT is the top of the source tree.
SRC_ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
BUILD_DIR=$(shell basename $(shell yq '.dist.output_path' 'manifest.yaml'))

FIND_MOD_ARGS=-type f -name "go.mod"
TO_MOD_DIR=dirname {} \; | sort | grep -E '^./'
DISTRIBUTIONS_MODS := $(shell find ./**/* $(FIND_MOD_ARGS) -exec $(TO_MOD_DIR) )

## Retrive all used dependencies in the same output
# RESULTS := $(foreach dir,$(DISTRIBUTIONS_MODS),$(shell cd $(dir) && go list -mod=mod -m -json all))
########################
#### Check targets #####
########################

.PHONY: assert_build-dir
assert_build-dir:
@test $(BUILD_DIR) = _build || (echo "expected build directory _build but was $(BUILD_DIR): required because it is hardcoded for goreleaser" && exit 1)

NOTICE_OUTPUT ?= THIRD_PARTY_NOTICES.md
GO_MOD_TMP_FILE ?= /tmp/tmp_notices.json

.PHONY: third-party-notices
third-party-notices: OUT ?= THIRD_PARTY_NOTICES.md
third-party-notices:
third-party-notices: assert_build-dir
@command -v go-licence-detector &> /dev/null || (echo "go-license-detector tool not found, install it from the base directory with \"make internal/tools\"" && exit 1)
$(foreach dir,$(DISTRIBUTIONS_MODS),$(shell cd $(dir) && go list -mod=mod -m -json all >> /tmp/tmp_notices.json))
@go-licence-detector \
-in /tmp/tmp_notices.json \
-rules $(SRC_ROOT)/internal/assets/license/rules.json \
-noticeTemplate $(SRC_ROOT)/internal/assets/license/THIRD_PARTY_NOTICES.md.tmpl \
-noticeOut $(OUT)
@echo '' > /tmp/tmp_notices.json
echo '' > $(GO_MOD_TMP_FILE);\
cd $(BUILD_DIR) && go list -mod=mod -m -json all >> $(GO_MOD_TMP_FILE);\
go-licence-detector \
-in $(GO_MOD_TMP_FILE) \
-rules $(SRC_ROOT)/internal/assets/license/rules.json \
-noticeTemplate $(SRC_ROOT)/internal/assets/license/THIRD_PARTY_NOTICES.md.tmpl \
-noticeOut $(NOTICE_OUTPUT)

.PHONY: third-party-notices-check
third-party-notices-check: third-party-notices
@git diff --name-only | grep -q "THIRD_PARTY_NOTICES.md" && { echo "Third party notices out of date, please run \"make licenses\" and commit the changes in this PR."; exit 1; } || exit 0
@git diff --name-only | grep -q $(NOTICE_OUTPUT) \
&& { \
echo "Third party notices out of date, please run \"make licenses\" and commit the changes in this PR.";\
echo "Diff of $(NOTICE_OUTPUT):";\
git --no-pager diff HEAD -- $(NOTICE_OUTPUT);\
echo "go.mod file used:";\
cat $(BUILD_DIR)/go.mod;\
exit 1;\
} \
|| exit 0


########################
#### Build targets #####
########################
DISTRO_NAME=$(shell basename $(shell pwd))
BINARY_NAME=$(shell yq '.dist.name' 'manifest.yaml')

build-distro: assert_build-dir $(BUILD_DIR)/$(BINARY_NAME)
$(BUILD_DIR)/$(BINARY_NAME): manifest.yaml
$(SRC_ROOT)/scripts/build.sh -d $(DISTRO_NAME)

generate-sources-for-distro: assert_build-dir $(BUILD_DIR)/go.mod
$(BUILD_DIR)/go.mod: manifest.yaml
$(SRC_ROOT)/scripts/build.sh -d $(DISTRO_NAME) -s true

.PHONY: clean-build-dir-distro
clean-build-dir-distro:
rm -rf $(BUILD_DIR)
65 changes: 10 additions & 55 deletions build.mk
Original file line number Diff line number Diff line change
@@ -1,59 +1,14 @@
GO ?= go
GORELEASER ?= goreleaser

OTELCOL_BUILDER_VERSION ?= 0.108.0
OTELCOL_BUILDER_DIR ?= ${HOME}/bin
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb

DISTRIBUTIONS ?= "nr-otel-collector"

.PHONY: ci
ci: build

build: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -b ${OTELCOL_BUILDER} -g ${GO}

generate: generate-sources

generate-sources: go ocb
@./scripts/build.sh -d "${DISTRIBUTIONS}" -s true -b ${OTELCOL_BUILDER} -g ${GO}

goreleaser-verify: goreleaser
@${GORELEASER} release --snapshot --rm-dist

.PHONY: ocb
ocb:
ifeq (, $(shell command -v ocb 2>/dev/null))
@{ \
[ ! -x '$(OTELCOL_BUILDER)' ] || exit 0; \
set -e ;\
os=$$(uname | tr A-Z a-z) ;\
machine=$$(uname -m) ;\
[ "$${machine}" != x86 ] || machine=386 ;\
[ "$${machine}" != x86_64 ] || machine=amd64 ;\
[ "$${machine}" != aarch64 ] || machine=arm64 ;\
echo "Installing ocb ($${os}/$${machine}) at $(OTELCOL_BUILDER_DIR)";\
mkdir -p $(OTELCOL_BUILDER_DIR) ;\
curl -sLo $(OTELCOL_BUILDER) "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/cmd%2Fbuilder%2Fv$(OTELCOL_BUILDER_VERSION)/ocb_$(OTELCOL_BUILDER_VERSION)_$${os}_$${machine}" ;\
chmod +x $(OTELCOL_BUILDER) ;\
}
else
OTELCOL_BUILDER=$(shell command -v ocb)
endif
.PHONY: build
build:
@$(MAKE) for-all-target TARGET="build-distro"

.PHONY: go
go:
@{ \
if ! command -v '$(GO)' >/dev/null 2>/dev/null; then \
echo >&2 '$(GO) command not found. Please install golang. https://go.dev/doc/install'; \
exit 1; \
fi \
}
.PHONY: generate-sources
generate-sources:
@$(MAKE) for-all-target TARGET="generate-sources-for-distro"

.PHONY: goreleaser
goreleaser:
@{ \
if ! command -v '$(GORELEASER)' >/dev/null 2>/dev/null; then \
echo >&2 '$(GORELEASER) command not found. Please install goreleaser. https://goreleaser.com/install/'; \
exit 1; \
fi \
}
.PHONY: clean-build-dir
clean-build-dir:
@$(MAKE) for-all-target TARGET="clean-build-dir-distro"
21 changes: 4 additions & 17 deletions check.mk
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@

GROUP ?= all
FOR_GROUP_TARGET=for-$(GROUP)-target

# Define a delegation target for each distribution
.PHONY: $(ALL_DISTRIBUTIONS)
$(ALL_DISTRIBUTIONS):
$(MAKE) -C $@ $(TARGET)

# Trigger each module's delegation target
.PHONY: for-all-target
for-all-target: $(ALL_DISTRIBUTIONS)

.PHONY: licenses
licenses: internal/tools build
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="third-party-notices"
licenses: internal/tools generate-sources
@$(MAKE) for-all-target TARGET="third-party-notices"

.PHONY: licenses-check
licenses-check: internal/tools build
@$(MAKE) $(FOR_GROUP_TARGET) TARGET="third-party-notices-check"
licenses-check: internal/tools generate-sources
@$(MAKE) for-all-target TARGET="third-party-notices-check"
12 changes: 6 additions & 6 deletions configs/nr-otel-collector-agent-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ processors:
override: true

exporters:
logging:
debug:
otlphttp:
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT}
headers:
Expand Down Expand Up @@ -230,22 +230,22 @@ service:
- resourcedetection/env
- cumulativetodelta
- batch
exporters: [logging, otlphttp]
exporters: [debug, otlphttp]
logs/host:
receivers: [filelog]
processors: [transform, resourcedetection, resourcedetection/cloud, resourcedetection/env, batch]
exporters: [logging, otlphttp]
exporters: [debug, otlphttp]
traces:
receivers: [otlp]
processors: [transform, resourcedetection, resourcedetection/cloud, resourcedetection/env, batch]
exporters: [logging, otlphttp]
exporters: [debug, otlphttp]
metrics:
receivers: [otlp]
processors: [transform, resourcedetection, resourcedetection/cloud, resourcedetection/env, batch]
exporters: [logging, otlphttp]
exporters: [debug, otlphttp]
logs:
receivers: [otlp]
processors: [transform, resourcedetection, resourcedetection/cloud, resourcedetection/env, batch]
exporters: [logging, otlphttp]
exporters: [debug, otlphttp]

extensions: [health_check]
6 changes: 3 additions & 3 deletions configs/nr-otel-collector-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ processors:
limit_mib: ${NEW_RELIC_MEMORY_LIMIT_MIB}

exporters:
logging:
debug:
verbosity: detailed
otlp:
endpoint: ${OTEL_EXPORTER_OTLP_ENDPOINT}
Expand All @@ -36,11 +36,11 @@ service:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [logging, otlp]
exporters: [debug, otlp]

metrics:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [logging, otlp]
exporters: [debug, otlp]

extensions: [health_check]
23 changes: 7 additions & 16 deletions distributions/nr-otel-collector/THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
# Third Party Notices

The New Relic infrastructure agent uses source code from third
party libraries which carry
their own copyright notices and license terms. These notices ar
e provided
below.
The New Relic infrastructure agent uses source code from third party libraries which carry their own copyright notices
and license terms. These notices are provided below.

In the event that a required notice is missing or incorrect, pl
ease notify us
either by [opening an issue](https://github.com/newrelic/infras
tructure-agent/issues/new),
or by e-mailing [open-source@newrelic.com](mailto:open-source@n
ewrelic.com).
In the event that a required notice is missing or incorrect, please notify us by e-mailing
[open-source@newrelic.com](mailto:open-source@newrelic.com).

For any licenses that require the disclosure of source code, th
e source code
can be found at https://github.com/newrelic/infrastructure-agen
t/.
For any licenses that require the disclosure of source code, the source code
can be found at https://github.com/newrelic/opentelemetry-collector-releases.



Expand Down Expand Up @@ -253,7 +244,7 @@ Distributed under the following license(s):



## [go.opentelemetry.io/collector/exporter/loggingexporter](https://go.opentelemetry.io/collector/exporter/loggingexporter)
## [go.opentelemetry.io/collector/exporter/debugexporter](https://go.opentelemetry.io/collector/exporter/debugexporter)

Distributed under the following license(s):

Expand Down
63 changes: 35 additions & 28 deletions distributions/nr-otel-collector/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,49 @@ dist:
description: New Relic OpenTelemetry Collector
version: 0.8.7
output_path: ./_build
otelcol_version: 0.108.0
otelcol_version: 0.112.0

extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.108.0
- gomod: go.opentelemetry.io/collector/extension/zpagesextension v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.112.0
- gomod: go.opentelemetry.io/collector/extension/zpagesextension v0.112.0

exporters:
- gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.108.0
- gomod: go.opentelemetry.io/collector/exporter/otlphttpexporter v0.108.0
- gomod: go.opentelemetry.io/collector/exporter/loggingexporter v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter v0.108.0
- gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.112.0
- gomod: go.opentelemetry.io/collector/exporter/otlphttpexporter v0.112.0
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/prometheusremotewriteexporter v0.112.0

processors:
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.108.0
- gomod: go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/filterprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.108.0
- gomod: go.opentelemetry.io/collector/processor/batchprocessor v0.112.0
- gomod: go.opentelemetry.io/collector/processor/memorylimiterprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/attributesprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/cumulativetodeltaprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/filterprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/groupbyattrsprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/metricstransformprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourceprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/transformprocessor v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor v0.112.0

receivers:
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8seventsreceiver v0.108.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver v0.108.0
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/statsdreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/redisreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/kubeletstatsreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8seventsreceiver v0.112.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver v0.112.0

providers:
- gomod: go.opentelemetry.io/collector/confmap/provider/envprovider v1.18.0
- gomod: go.opentelemetry.io/collector/confmap/provider/fileprovider v1.18.0
- gomod: go.opentelemetry.io/collector/confmap/provider/httpprovider v1.18.0
- gomod: go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.18.0
- gomod: go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.18.0

# When adding a replace, add a comment before it to document why it's needed and when it can be removed
replaces:
Expand Down
25 changes: 8 additions & 17 deletions internal/assets/license/THIRD_PARTY_NOTICES.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@ Distributed under the following license(s):

# Third Party Notices

The New Relic infrastructure agent uses source code from third
party libraries which carry
their own copyright notices and license terms. These notices ar
e provided
below.

In the event that a required notice is missing or incorrect, pl
ease notify us
either by [opening an issue](https://github.com/newrelic/infras
tructure-agent/issues/new),
or by e-mailing [open-source@newrelic.com](mailto:open-source@n
ewrelic.com).

For any licenses that require the disclosure of source code, th
e source code
can be found at https://github.com/newrelic/infrastructure-agen
t/.
The New Relic infrastructure agent uses source code from third party libraries which carry their own copyright notices
and license terms. These notices are provided below.

In the event that a required notice is missing or incorrect, please notify us by e-mailing
[open-source@newrelic.com](mailto:open-source@newrelic.com).

For any licenses that require the disclosure of source code, the source code
can be found at https://github.com/newrelic/opentelemetry-collector-releases.


{{ template "depInfo" .Direct }}
Expand Down
Loading

0 comments on commit e11d2bd

Please sign in to comment.