Skip to content

Commit b20e4d1

Browse files
author
Bogdan Drutu
authored
Merge pull request open-telemetry#1 from signalfx/initialcommit
Initial commit of the splunk otel collector distribution
2 parents d540f6e + c0cbd08 commit b20e4d1

15 files changed

+2724
-0
lines changed

.gitignore

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
bin/
2+
dist/
3+
4+
# GoLand IDEA
5+
/.idea/
6+
*.iml
7+
8+
# VS Code
9+
.vscode
10+
11+
# Emacs
12+
*~
13+
\#*\#
14+
15+
# Miscellaneous files
16+
*.sw[op]
17+
*.DS_Store
18+
19+
# Coverage
20+
coverage.txt
21+
coverage_all.txt
22+
coverage_old.txt
23+
coverage.html
24+
25+
# Wix
26+
*.wixobj
27+
*.wixpdb

.golangci.yml

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# options for analysis running
2+
run:
3+
# default concurrency is a available CPU number
4+
concurrency: 4
5+
6+
# timeout for analysis, e.g. 30s, 5m, default is 1m
7+
timeout: 10m
8+
9+
# exit code when at least one issue was found, default is 1
10+
issues-exit-code: 1
11+
12+
# include test files or not, default is true
13+
tests: true
14+
15+
# which dirs to skip: issues from them won't be reported;
16+
# can use regexp here: generated.*, regexp is applied on full path;
17+
# default value is empty list, but default dirs are skipped independently
18+
# from this option's value (see skip-dirs-use-default).
19+
skip-dirs:
20+
21+
# default is true. Enables skipping of directories:
22+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
23+
skip-dirs-use-default: false
24+
25+
# which files to skip: they will be analyzed, but issues from them
26+
# won't be reported. Default value is empty list, but there is
27+
# no need to include all autogenerated files, we confidently recognize
28+
# autogenerated files. If it's not please let us know.
29+
skip-files:
30+
31+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
32+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
33+
# automatic updating of go.mod described above. Instead, it fails when any changes
34+
# to go.mod are needed. This setting is most useful to check that go.mod does
35+
# not need updates, such as in a continuous integration and testing system.
36+
# If invoked with -mod=vendor, the go command assumes that the vendor
37+
# directory holds the correct copies of dependencies and ignores
38+
# the dependency descriptions in go.mod.
39+
modules-download-mode: readonly
40+
41+
# output configuration options
42+
output:
43+
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
44+
format: colored-line-number
45+
46+
# print lines of code with issue, default is true
47+
print-issued-lines: true
48+
49+
# print linter name in the end of issue text, default is true
50+
print-linter-name: true
51+
52+
# all available settings of specific linters
53+
linters-settings:
54+
govet:
55+
# report about shadowed variables
56+
check-shadowing: true
57+
58+
# settings per analyzer
59+
settings:
60+
printf: # analyzer name, run `go tool vet help` to see all analyzers
61+
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
62+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
63+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
64+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
65+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
66+
67+
enable-all: true
68+
69+
golint:
70+
# minimal confidence for issues, default is 0.8
71+
min-confidence: 0.8
72+
gofmt:
73+
# simplify code: gofmt with `-s` option, true by default
74+
simplify: true
75+
goimports:
76+
# put imports beginning with prefix after 3rd-party packages;
77+
# it's a comma-separated list of prefixes
78+
local-prefixes: github.com/signalfx/splunk-otel-collector
79+
misspell:
80+
# Correct spellings using locale preferences for US or UK.
81+
# Default is to use a neutral variety of English.
82+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
83+
locale: US
84+
ignore-words:
85+
- cancelled
86+
- metre
87+
- meter
88+
- metres
89+
- kilometre
90+
- kilometres
91+
92+
linters:
93+
disable:
94+
- errcheck
95+
enable:
96+
- gofmt
97+
- goimports
98+
- golint
99+
- govet
100+
- staticcheck
101+
- misspell
102+
- scopelint
103+
- unconvert
104+
- gocritic
105+
106+
issues:
107+
# Excluding configuration per-path, per-linter, per-text and per-source
108+
exclude-rules:
109+
# Exclude some linters from running on tests files.
110+
- path: _test\.go
111+
linters:
112+
- scopelint

Makefile

+183
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# All source code excluding any third party code and excluding the testbed.
2+
# This is the code that we want to run tests for and lint, staticcheck, etc.
3+
ALL_SRC := $(shell find . -name '*.go' \
4+
-not -path './examples/*' \
5+
-type f | sort)
6+
7+
# ALL_PKGS is the list of all packages where ALL_SRC files reside.
8+
ALL_PKGS := $(shell go list $(sort $(dir $(ALL_SRC))))
9+
10+
# All source code and documents. Used in spell check.
11+
ALL_DOC := $(shell find . \( -name "*.md" -o -name "*.yaml" \) \
12+
-type f | sort)
13+
14+
GOTEST_OPT?= -v -race -timeout 180s
15+
GO_ACC=go-acc
16+
GOTEST=go test
17+
GOOS=$(shell go env GOOS)
18+
GOARCH=$(shell go env GOARCH)
19+
ADDLICENSE= addlicense
20+
MISSPELL=misspell -error
21+
MISSPELL_CORRECTION=misspell -w
22+
LINT=golangci-lint
23+
IMPI=impi
24+
GOSEC=gosec
25+
STATIC_CHECK=staticcheck
26+
# BUILD_TYPE should be one of (dev, release).
27+
BUILD_TYPE?=release
28+
29+
GIT_SHA=$(shell git rev-parse --short HEAD)
30+
BUILD_INFO_IMPORT_PATH=github.com/signalfx/splunk-otel-collector/internal/version
31+
BUILD_X1=-X $(BUILD_INFO_IMPORT_PATH).GitHash=$(GIT_SHA)
32+
ifdef VERSION
33+
BUILD_X2=-X $(BUILD_INFO_IMPORT_PATH).Version=$(VERSION)
34+
endif
35+
BUILD_X3=-X $(BUILD_INFO_IMPORT_PATH).BuildType=$(BUILD_TYPE)
36+
BUILD_INFO=-ldflags "${BUILD_X1} ${BUILD_X2} ${BUILD_X3}"
37+
38+
# Function to execute a command. Note the empty line before endef to make sure each command
39+
# gets executed separately instead of concatenated with previous one.
40+
# Accepts command to execute as first parameter.
41+
define exec-command
42+
$(1)
43+
44+
endef
45+
46+
all-srcs:
47+
@echo $(ALL_SRC) | tr ' ' '\n' | sort
48+
49+
all-pkgs:
50+
@echo $(ALL_PKGS) | tr ' ' '\n' | sort
51+
52+
.DEFAULT_GOAL := all
53+
54+
.PHONY: all
55+
all: checklicense impi lint misspell test otelcol
56+
57+
.PHONY: test
58+
test:
59+
$(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)
60+
61+
.PHONY: test-with-cover
62+
test-with-cover:
63+
@echo Verifying that all packages have test files to count in coverage
64+
@internal/buildscripts/check-test-files.sh $(subst go.opentelemetry.io/collector,.,$(ALL_PKGS))
65+
@echo pre-compiling tests
66+
@time go test -i $(ALL_PKGS)
67+
$(GO_ACC) $(ALL_PKGS)
68+
go tool cover -html=coverage.txt -o coverage.html
69+
70+
.PHONY: addlicense
71+
addlicense:
72+
$(ADDLICENSE) -y "" -c 'The OpenTelemetry Authors' $(ALL_SRC)
73+
74+
.PHONY: checklicense
75+
checklicense:
76+
@ADDLICENSEOUT=`$(ADDLICENSE) -check $(ALL_SRC) 2>&1`; \
77+
if [ "$$ADDLICENSEOUT" ]; then \
78+
echo "$(ADDLICENSE) FAILED => add License errors:\n"; \
79+
echo "$$ADDLICENSEOUT\n"; \
80+
echo "Use 'make addlicense' to fix this."; \
81+
exit 1; \
82+
else \
83+
echo "Check License finished successfully"; \
84+
fi
85+
86+
.PHONY: misspell
87+
misspell:
88+
$(MISSPELL) $(ALL_DOC)
89+
90+
.PHONY: misspell-correction
91+
misspell-correction:
92+
$(MISSPELL_CORRECTION) $(ALL_DOC)
93+
94+
.PHONY: lint-gosec
95+
lint-gosec:
96+
# TODO: Consider to use gosec from golangci-lint
97+
$(GOSEC) -quiet -exclude=G104 $(ALL_PKGS)
98+
99+
.PHONY: lint-static-check
100+
lint-static-check:
101+
@STATIC_CHECK_OUT=`$(STATIC_CHECK) $(ALL_PKGS) 2>&1`; \
102+
if [ "$$STATIC_CHECK_OUT" ]; then \
103+
echo "$(STATIC_CHECK) FAILED => static check errors:\n"; \
104+
echo "$$STATIC_CHECK_OUT\n"; \
105+
exit 1; \
106+
else \
107+
echo "Static check finished successfully"; \
108+
fi
109+
110+
.PHONY: lint
111+
lint: lint-static-check
112+
$(LINT) run
113+
114+
.PHONY: impi
115+
impi:
116+
@$(IMPI) --local github.com/signalfx/splunk-otel-collector --scheme stdThirdPartyLocal --skip internal/data/opentelemetry-proto ./...
117+
118+
.PHONY: install-tools
119+
install-tools:
120+
go install github.com/client9/misspell/cmd/misspell
121+
go install github.com/golangci/golangci-lint/cmd/golangci-lint
122+
go install github.com/google/addlicense
123+
go install github.com/ory/go-acc
124+
go install github.com/pavius/impi/cmd/impi
125+
go install github.com/securego/gosec/cmd/gosec
126+
go install honnef.co/go/tools/cmd/staticcheck
127+
128+
.PHONY: otelcol
129+
otelcol:
130+
go generate ./...
131+
GO111MODULE=on CGO_ENABLED=0 go build -o ./bin/otelcol_$(GOOS)_$(GOARCH)$(EXTENSION) $(BUILD_INFO) ./cmd/otelcol
132+
133+
.PHONY: add-tag
134+
add-tag:
135+
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
136+
@echo "Adding tag ${TAG}"
137+
@git tag -a ${TAG} -s -m "Version ${TAG}"
138+
139+
.PHONY: delete-tag
140+
delete-tag:
141+
@[ "${TAG}" ] || ( echo ">> env var TAG is not set"; exit 1 )
142+
@echo "Deleting tag ${TAG}"
143+
@git tag -d ${TAG}
144+
145+
.PHONY: docker-otelcol
146+
docker-otelcol:
147+
COMPONENT=otelcol $(MAKE) docker-component
148+
149+
.PHONY: docker-component # Not intended to be used directly
150+
docker-component:
151+
GOOS=linux $(MAKE) $(COMPONENT)
152+
cp ./bin/$(COMPONENT)_linux_amd64 ./cmd/$(COMPONENT)/$(COMPONENT)
153+
docker build -t $(COMPONENT) ./cmd/$(COMPONENT)/
154+
rm ./cmd/$(COMPONENT)/$(COMPONENT)
155+
156+
.PHONY: binaries
157+
binaries: otelcol
158+
159+
.PHONY: binaries-all-sys
160+
binaries-all-sys: binaries-darwin_amd64 binaries-linux_amd64 binaries-linux_arm64 binaries-windows_amd64
161+
162+
.PHONY: binaries-darwin_amd64
163+
binaries-darwin_amd64:
164+
GOOS=darwin GOARCH=amd64 $(MAKE) binaries
165+
166+
.PHONY: binaries-linux_amd64
167+
binaries-linux_amd64:
168+
GOOS=linux GOARCH=amd64 $(MAKE) binaries
169+
170+
.PHONY: binaries-linux_arm64
171+
binaries-linux_arm64:
172+
GOOS=linux GOARCH=arm64 $(MAKE) binaries
173+
174+
.PHONY: binaries-windows_amd64
175+
binaries-windows_amd64:
176+
GOOS=windows GOARCH=amd64 EXTENSION=.exe $(MAKE) binaries
177+
178+
.PHONY: deb-rpm-package
179+
%-package: ARCH ?= amd64
180+
%-package:
181+
$(MAKE) binaries-linux_$(ARCH)
182+
docker build -t otelcol-fpm internal/buildscripts/packaging/fpm
183+
docker run --rm -v $(CURDIR):/repo -e PACKAGE=$* -e VERSION=$(VERSION) -e ARCH=$(ARCH) otelcol-fpm

cmd/otelcol/Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM alpine:3.12 as certs
2+
RUN apk --update add ca-certificates
3+
4+
FROM alpine:3.12 AS otelcol
5+
COPY otelcol /
6+
# Note that this shouldn't be necessary, but in some cases the file seems to be
7+
# copied with the execute bit lost (see #1317)
8+
RUN chmod 755 /otelcol
9+
10+
FROM scratch
11+
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
12+
COPY --from=otelcol /otelcol /
13+
COPY config.yaml /etc/otel/config.yaml
14+
ENTRYPOINT ["/otelcol"]
15+
CMD ["--config", "/etc/otel/config.yaml"]
16+
EXPOSE 55678 55679

cmd/otelcol/config.yaml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
extensions:
2+
health_check:
3+
pprof:
4+
endpoint: 0.0.0.0:1777
5+
zpages:
6+
endpoint: 0.0.0.0:55679
7+
8+
receivers:
9+
otlp:
10+
protocols:
11+
grpc:
12+
http:
13+
14+
opencensus:
15+
16+
# Collect own metrics
17+
prometheus:
18+
config:
19+
scrape_configs:
20+
- job_name: 'otel-collector'
21+
scrape_interval: 10s
22+
static_configs:
23+
- targets: ['0.0.0.0:8888']
24+
25+
jaeger:
26+
protocols:
27+
grpc:
28+
thrift_binary:
29+
thrift_compact:
30+
thrift_http:
31+
32+
zipkin:
33+
34+
processors:
35+
batch:
36+
37+
exporters:
38+
logging:
39+
logLevel: debug
40+
41+
service:
42+
43+
pipelines:
44+
45+
traces:
46+
receivers: [opencensus, jaeger, zipkin]
47+
processors: [batch]
48+
exporters: [logging]
49+
50+
metrics:
51+
receivers: [otlp, opencensus, prometheus]
52+
processors: [batch]
53+
exporters: [logging]
54+
55+
extensions: [health_check, pprof, zpages]

0 commit comments

Comments
 (0)