-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce custom collector
- Loading branch information
0 parents
commit 570ad38
Showing
18 changed files
with
2,056 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
include ./Makefile.Common | ||
|
||
RUN_CONFIG=local/config.yaml | ||
|
||
CMD?= | ||
GIT_SHA=$(shell git rev-parse --short HEAD) | ||
BUILD_INFO_IMPORT_PATH=github.com/tigrannajaryan/custcol/internal/version | ||
BUILD_X1=-X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA) | ||
ifdef VERSION | ||
BUILD_X2=-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION) | ||
endif | ||
BUILD_X3=-X go.opentelemetry.io/collector/internal/version.BuildType=$(BUILD_TYPE) | ||
BUILD_INFO=-ldflags "${BUILD_X1} ${BUILD_X2} ${BUILD_X3}" | ||
STATIC_CHECK=staticcheck | ||
OTEL_VERSION=master | ||
|
||
EXE_NAME=custcol | ||
|
||
# Modules to run integration tests on. | ||
# XXX: Find a way to automatically populate this. Too slow to run across all modules when there are just a few. | ||
INTEGRATION_TEST_MODULES := \ | ||
internal/common | ||
|
||
.DEFAULT_GOAL := all | ||
|
||
.PHONY: all | ||
all: common build-exe | ||
|
||
.PHONY: test-with-cover | ||
unit-tests-with-cover: | ||
@echo Verifying that all packages have test files to count in coverage | ||
@internal/buildscripts/check-test-files.sh $(subst github.com/tigrannajaryan/custcol/,./,$(ALL_PKGS)) | ||
@$(MAKE) for-all CMD="make do-unit-tests-with-cover" | ||
|
||
.PHONY: integration-tests-with-cover | ||
integration-tests-with-cover: | ||
@echo $(INTEGRATION_TEST_MODULES) | ||
@$(MAKE) for-all CMD="make do-integration-tests-with-cover" ALL_MODULES="$(INTEGRATION_TEST_MODULES)" | ||
|
||
.PHONY: gotidy | ||
gotidy: | ||
$(MAKE) for-all CMD="rm -fr go.sum" | ||
$(MAKE) for-all CMD="go mod tidy" | ||
|
||
.PHONY: gofmt | ||
gofmt: | ||
$(MAKE) for-all CMD="make fmt" | ||
|
||
.PHONY: for-all | ||
for-all: | ||
@echo "running $${CMD} in root" | ||
@$${CMD} | ||
@set -e; for dir in $(ALL_MODULES); do \ | ||
(cd "$${dir}" && \ | ||
echo "running $${CMD} in $${dir}" && \ | ||
$${CMD} ); \ | ||
done | ||
|
||
.PHONY: add-tag | ||
add-tag: | ||
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 ) | ||
@echo "Adding tag ${TAG}" | ||
@git tag -a ${TAG} -s -m "Version ${TAG}" | ||
@set -e; for dir in $(ALL_MODULES); do \ | ||
(echo Adding tag "$${dir:2}/$${TAG}" && \ | ||
git tag -a "$${dir:2}/$${TAG}" -s -m "Version ${dir:2}/${TAG}" ); \ | ||
done | ||
|
||
.PHONY: delete-tag | ||
delete-tag: | ||
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 ) | ||
@echo "Deleting tag ${TAG}" | ||
@git tag -d ${TAG} | ||
@set -e; for dir in $(ALL_MODULES); do \ | ||
(echo Deleting tag "$${dir:2}/$${TAG}" && \ | ||
git tag -d "$${dir:2}/$${TAG}" ); \ | ||
done | ||
|
||
GOMODULES = $(ALL_MODULES) $(PWD) | ||
.PHONY: $(GOMODULES) | ||
MODULEDIRS = $(GOMODULES:%=for-all-target-%) | ||
for-all-target: $(MODULEDIRS) | ||
$(MODULEDIRS): | ||
$(MAKE) -C $(@:for-all-target-%=%) $(TARGET) | ||
.PHONY: for-all-target | ||
|
||
.PHONY: install-tools | ||
install-tools: | ||
go install github.com/client9/misspell/cmd/misspell | ||
go install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
go install github.com/google/addlicense | ||
go install github.com/jstemmer/go-junit-report | ||
go install github.com/pavius/impi/cmd/impi | ||
go install github.com/tcnksm/ghr | ||
go install honnef.co/go/tools/cmd/staticcheck | ||
go install go.opentelemetry.io/collector/cmd/issuegenerator | ||
|
||
.PHONY: run | ||
run: | ||
./bin/$(EXE_NAME)_darwin_amd64 --config ./cmd/$(EXE_NAME)/config.yaml --log-level DEBUG | ||
|
||
.PHONY: docker-component # Not intended to be used directly | ||
docker-component: check-component | ||
GOOS=linux GOARCH=amd64 $(MAKE) $(COMPONENT) | ||
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT) | ||
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/ | ||
rm ./cmd/$(COMPONENT)/$(COMPONENT) | ||
|
||
.PHONY: check-component | ||
check-component: | ||
ifndef COMPONENT | ||
$(error COMPONENT variable was not defined) | ||
endif | ||
|
||
.PHONY: build-exe | ||
build-exe: | ||
GO111MODULE=on CGO_ENABLED=0 go build -o ./bin/$(EXE_NAME)_$(GOOS)_$(GOARCH)$(EXTENSION) $(BUILD_INFO) ./cmd/$(EXE_NAME) | ||
|
||
.PHONY: build-all-sys | ||
build-all-sys: build-darwin_amd64 build-linux_amd64 | ||
|
||
.PHONY: build-darwin_amd64 | ||
build-darwin_amd64: | ||
GOOS=darwin GOARCH=amd64 $(MAKE) build-exe | ||
|
||
.PHONY: build-linux_amd64 | ||
build-linux_amd64: | ||
GOOS=linux GOARCH=amd64 $(MAKE) build-exe | ||
|
||
.PHONY: update-dep | ||
update-dep: | ||
$(MAKE) for-all CMD="$(PWD)/internal/buildscripts/update-dep" | ||
$(MAKE) build-exe | ||
$(MAKE) gotidy | ||
|
||
.PHONY: update-otel | ||
update-otel: | ||
$(MAKE) update-dep MODULE=go.opentelemetry.io/collector VERSION=$(OTEL_VERSION) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# SRC_ROOT is the top of the source tree. | ||
SRC_ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
|
||
ALL_SRC := $(shell find . -name '*.go' \ | ||
-type f | sort) | ||
|
||
# All source code and documents. Used in spell check. | ||
ALL_SRC_AND_DOC := $(shell find . \( -name "*.md" -o -name "*.go" -o -name "*.yaml" \) \ | ||
-type f | sort) | ||
|
||
# ALL_PKGS is used with 'go cover' | ||
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))) 2>/dev/null) | ||
# ALL_MODULES includes ./* dirs (excludes . dir) | ||
ALL_MODULES := $(shell find . -type f -name "go.mod" -exec dirname {} \; | sort | egrep '^./' ) | ||
|
||
GOTEST_OPT?= -race -timeout 30s | ||
GOTEST_OPT_WITH_COVERAGE = $(GOTEST_OPT) -coverprofile=coverage.txt -covermode=atomic | ||
GOTEST_OPT_WITH_INTEGRATION=$(GOTEST_OPT) -v -tags=integration -run=Integration -coverprofile=integration-coverage.txt -covermode=atomic | ||
GOTEST=go test | ||
GOOS=$(shell go env GOOS) | ||
GOARCH=$(shell go env GOARCH) | ||
ADDLICENCESE= addlicense | ||
MISSPELL=misspell -error | ||
MISSPELL_CORRECTION=misspell -w | ||
STATICCHECK=staticcheck | ||
LINT=golangci-lint | ||
IMPI=impi | ||
# BUILD_TYPE should be one of (dev, release). | ||
BUILD_TYPE?=release | ||
|
||
all-modules: | ||
@echo $(ALL_MODULES) | tr ' ' '\n' | sort | ||
|
||
all-pkgs: | ||
@echo $(ALL_PKGS) | tr ' ' '\n' | sort | ||
|
||
all-srcs: | ||
@echo $(ALL_SRC) | tr ' ' '\n' | sort | ||
|
||
.DEFAULT_GOAL := common | ||
|
||
.PHONY: common | ||
common: impi test | ||
|
||
.PHONY: test | ||
test: | ||
@set -e; for dir in $(ALL_MODULES); do \ | ||
echo "go test ./... in $${dir}"; \ | ||
(cd "$${dir}" && \ | ||
$(GOTEST) ./... ); \ | ||
done | ||
|
||
.PHONY: do-unit-tests-with-cover | ||
do-unit-tests-with-cover: | ||
@echo "running go unit test ./... + coverage in `pwd`" | ||
@$(GOTEST) $(GOTEST_OPT_WITH_COVERAGE) ./... | ||
go tool cover -html=coverage.txt -o coverage.html | ||
|
||
.PHONY: run-integration-tests-with-cover | ||
do-integration-tests-with-cover: | ||
@echo "running go integration test ./... + coverage in `pwd`" | ||
@$(GOTEST) $(GOTEST_OPT_WITH_INTEGRATION) ./... | ||
@if [ -e integration-coverage.txt ]; then \ | ||
go tool cover -html=integration-coverage.txt -o integration-coverage.html; \ | ||
fi | ||
|
||
.PHONY: benchmark | ||
benchmark: | ||
$(GOTEST) -bench=. -run=notests $(ALL_PKGS) | ||
|
||
.PHONY: addlicense | ||
addlicense: | ||
@ADDLICENCESEOUT=`$(ADDLICENCESE) -y -c 'OpenTelemetry Authors' $(ALL_SRC) 2>&1`; \ | ||
if [ "$$ADDLICENCESEOUT" ]; then \ | ||
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \ | ||
echo "$$ADDLICENCESEOUT\n"; \ | ||
exit 1; \ | ||
else \ | ||
echo "Add License finished successfully"; \ | ||
fi | ||
|
||
.PHONY: checklicense | ||
checklicense: | ||
@ADDLICENCESEOUT=`$(ADDLICENCESE) -check $(ALL_SRC) 2>&1`; \ | ||
if [ "$$ADDLICENCESEOUT" ]; then \ | ||
echo "$(ADDLICENCESE) FAILED => add License errors:\n"; \ | ||
echo "$$ADDLICENCESEOUT\n"; \ | ||
echo "Use 'make addlicense' to fix this."; \ | ||
exit 1; \ | ||
else \ | ||
echo "Check License finished successfully"; \ | ||
fi | ||
|
||
.PHONY: lint-static-check | ||
lint-static-check: | ||
@STATIC_CHECK_OUT=`$(STATICCHECK) ./... 2>&1`; \ | ||
if [ "$$STATIC_CHECK_OUT" ]; then \ | ||
echo "$(STATICCHECK) FAILED => static check errors:\n"; \ | ||
echo "$$STATIC_CHECK_OUT\n"; \ | ||
exit 1; \ | ||
else \ | ||
echo "Static check finished successfully"; \ | ||
fi | ||
|
||
|
||
.PHONY: fmt | ||
fmt: | ||
gofmt -w -s ./ | ||
goimports -w -local github.com/tigrannajaryan/custcol ./ | ||
|
||
.PHONY: lint | ||
lint: lint-static-check | ||
$(LINT) run --allow-parallel-runners | ||
|
||
.PHONY: misspell | ||
misspell: | ||
$(MISSPELL) $(ALL_SRC_AND_DOC) | ||
|
||
.PHONY: misspell-correction | ||
misspell-correction: | ||
$(MISSPELL_CORRECTION) $(ALL_SRC_AND_DOC) | ||
|
||
.PHONY: impi | ||
impi: | ||
@$(IMPI) --local github.com/tigrannajaryan/custcol --scheme stdThirdPartyLocal ./... | ||
|
||
.PHONY: dep | ||
dep: | ||
go mod download |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Custom Collector based on OpenTelemetry Collector | ||
|
||
To build: `make`. | ||
|
||
To run: `make run`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM alpine:latest as certs | ||
RUN apk --update add ca-certificates | ||
|
||
FROM scratch | ||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY custcol / | ||
EXPOSE 55680 55679 | ||
ENTRYPOINT ["/custcol"] | ||
CMD ["--config", "/etc/otel/config.yaml"] |
Oops, something went wrong.