Skip to content

Commit

Permalink
Implement Telemetry Schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
tigrannajaryan committed Sep 14, 2021
1 parent 570ad38 commit 886822b
Show file tree
Hide file tree
Showing 38 changed files with 2,360 additions and 748 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15

- name: Build
run: make install-tools && make build-all

- name: Test
run: make test
2 changes: 1 addition & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/exp-invsvc.iml → .idea/telemetry-schema.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 7 additions & 104 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,96 +4,25 @@ 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
EXE_NAME=telschema

.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
all: build-all test

.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
.PHONY: build-all
build-all: build-scheck

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: build-scheck
build-scheck:
go build -o bin/scheck ./cmd/scheck

.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:
Expand All @@ -111,29 +40,3 @@ 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)

112 changes: 25 additions & 87 deletions Makefile.Common
Original file line number Diff line number Diff line change
Expand Up @@ -2,128 +2,66 @@
SRC_ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))

ALL_SRC := $(shell find . -name '*.go' \
-not -path '*/third_party/*' \
-type f | sort)

# ALL_PKGS is the list of all packages where ALL_SRC files reside.
ALL_PKGS := $(shell go list ./...)

# All source code and documents. Used in spell check.
ALL_SRC_AND_DOC := $(shell find . \( -name "*.md" -o -name "*.go" -o -name "*.yaml" \) \
ALL_DOC := $(shell find . \( -name "*.md" -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_OPT?= -v -race -timeout 180s
GO_ACC=go-acc
GOTEST=go test
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
ADDLICENCESE= addlicense
MISSPELL=misspell -error
MISSPELL_CORRECTION=misspell -w
STATICCHECK=staticcheck
STATIC_CHECK=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
@echo "running go unit test ./... in `pwd`"
@echo $(ALL_PKGS) | xargs -n 10 $(GOTEST) $(GOTEST_OPT)

.PHONY: benchmark
benchmark:
$(GOTEST) -bench=. -run=notests $(ALL_PKGS)
$(GOTEST) -bench=. -run=notests ./...

.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: fmt
fmt:
gofmt -w -s ./
goimports -w -local github.com/tigrannajaryan/telemetry-schema ./

.PHONY: lint-static-check
lint-static-check:
@STATIC_CHECK_OUT=`$(STATICCHECK) ./... 2>&1`; \
@STATIC_CHECK_OUT=`$(STATIC_CHECK) $(ALL_PKGS) 2>&1`; \
if [ "$$STATIC_CHECK_OUT" ]; then \
echo "$(STATICCHECK) FAILED => static check errors:\n"; \
echo "$(STATIC_CHECK) 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:
$(LINT) run --allow-parallel-runners

.PHONY: misspell
misspell:
$(MISSPELL) $(ALL_SRC_AND_DOC)
ifdef ALL_DOC
$(MISSPELL) $(ALL_DOC)
endif

.PHONY: misspell-correction
misspell-correction:
$(MISSPELL_CORRECTION) $(ALL_SRC_AND_DOC)
ifdef ALL_DOC
$(MISSPELL_CORRECTION) $(ALL_DOC)
endif

.PHONY: impi
impi:
@$(IMPI) --local github.com/tigrannajaryan/custcol --scheme stdThirdPartyLocal ./...

.PHONY: dep
dep:
go mod download
@$(IMPI) --local github.com/tigrannajaryan/telemetry-schema --scheme stdThirdPartyLocal ./...
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Custom Collector based on OpenTelemetry Collector
# Telemetry Schema Prototype

This is a prototype that implements OpenTelemetry
[OTEP 0152](https://github.com/open-telemetry/oteps/pull/152)

To build: `make`.

To run: `make run`.
To run benchmarks: `make benchmark`.
9 changes: 0 additions & 9 deletions cmd/custcol/Dockerfile

This file was deleted.

Loading

0 comments on commit 886822b

Please sign in to comment.