-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[exporter/clickhouse] Implement consume log logic (#8028)
* [exporter/clickhouse] Implement consume log logic Signed-off-by: Jimmie Han <hanjinming@outlook.com>
- Loading branch information
Showing
21 changed files
with
778 additions
and
45 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
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
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 |
---|---|---|
@@ -1 +1,8 @@ | ||
include ../../Makefile.Common | ||
|
||
local-run-example: | ||
cd ../../ && GOOS=linux go build -o ./local/otelcontribcol ./cmd/otelcontribcol | ||
cd example && docker-compose up -d | ||
recreate-otel-collector: | ||
cd ../../ && GOOS=linux go build -o ./local/otelcontribcol ./cmd/otelcontribcol | ||
cd example && docker-compose up --build otel-collector |
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
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
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,74 @@ | ||
// Copyright 2020, OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package clickhouseexporter | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/config" | ||
"go.opentelemetry.io/collector/exporter/exporterhelper" | ||
"go.opentelemetry.io/collector/service/servicetest" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
factories, err := componenttest.NopFactories() | ||
require.NoError(t, err) | ||
|
||
factory := NewFactory() | ||
factories.Exporters[typeStr] = factory | ||
cfg, err := servicetest.LoadConfigAndValidate(filepath.Join("testdata", "config.yaml"), factories) | ||
require.NoError(t, err) | ||
require.NotNil(t, cfg) | ||
|
||
assert.Equal(t, len(cfg.Exporters), 2) | ||
|
||
defaultCfg := factory.CreateDefaultConfig() | ||
defaultCfg.(*Config).DSN = "tcp://127.0.0.1:9000?database=default" | ||
r0 := cfg.Exporters[config.NewComponentID(typeStr)] | ||
assert.Equal(t, r0, defaultCfg) | ||
|
||
r1 := cfg.Exporters[config.NewComponentIDWithName(typeStr, "full")].(*Config) | ||
assert.Equal(t, r1, &Config{ | ||
ExporterSettings: config.NewExporterSettings(config.NewComponentIDWithName(typeStr, "full")), | ||
DSN: "tcp://127.0.0.1:9000?database=default", | ||
TTLDays: 3, | ||
LogsTableName: "otel_logs", | ||
TimeoutSettings: exporterhelper.TimeoutSettings{ | ||
Timeout: 5 * time.Second, | ||
}, | ||
RetrySettings: exporterhelper.RetrySettings{ | ||
Enabled: true, | ||
InitialInterval: 5 * time.Second, | ||
MaxInterval: 30 * time.Second, | ||
MaxElapsedTime: 300 * time.Second, | ||
}, | ||
QueueSettings: QueueSettings{ | ||
QueueSize: 100, | ||
}, | ||
}) | ||
} | ||
|
||
func withDefaultConfig(fns ...func(*Config)) *Config { | ||
cfg := createDefaultConfig().(*Config) | ||
for _, fn := range fns { | ||
fn(cfg) | ||
} | ||
return cfg | ||
} |
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,12 @@ | ||
FROM alpine:latest as certs | ||
RUN apk --update add ca-certificates | ||
|
||
FROM scratch | ||
|
||
ARG USER_UID=10001 | ||
USER ${USER_UID} | ||
|
||
COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt | ||
COPY ./otelcontribcol /otelcontribcol | ||
ENTRYPOINT ["/otelcontribcol"] | ||
EXPOSE 4317 55680 55679 |
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,17 @@ | ||
# config file version | ||
apiVersion: 1 | ||
|
||
datasources: | ||
- name: ClickHouse-official | ||
type: grafana-clickhouse-datasource | ||
jsonData: | ||
defaultDatabase: default | ||
port: 9000 | ||
server: clickhouse | ||
username: | ||
tlsSkipVerify: true | ||
secureJsonData: | ||
password: | ||
- name: ClickHouse-vertamedia | ||
type: vertamedia-clickhouse-datasource | ||
url: http://clickhouse:8123 |
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,69 @@ | ||
version: "3" | ||
|
||
networks: | ||
otel-clickhouse: | ||
|
||
services: | ||
otel-collector: | ||
build: | ||
context: ../../../local | ||
dockerfile: ../exporter/clickhouseexporter/example/Dockerfile | ||
# Uncomment the next line to use a preexisting image | ||
# image: otelcontribcol:latest | ||
container_name: otel | ||
command: | ||
- "--config=/etc/otel-collector-config.yml" | ||
- "--set=service.telemetry.logs.level=DEBUG" | ||
volumes: | ||
- ./otel-collector-config.yml:/etc/otel-collector-config.yml | ||
ports: | ||
- "1888:1888" # pprof extension | ||
- "8888:8888" # Prometheus metrics exposed by the collector | ||
- "13133:13133" # health_check extension | ||
- "55679:55679" # zpages extension | ||
- "24224:24224" # fluentforwarder | ||
- "24224:24224/udp" # fluentforwarder | ||
depends_on: | ||
- clickhouse | ||
networks: | ||
- otel-clickhouse | ||
|
||
clickhouse: | ||
image: clickhouse/clickhouse-server:latest | ||
ports: | ||
- "9000:9000" | ||
- "8123:8123" | ||
networks: | ||
- otel-clickhouse | ||
|
||
grafana: | ||
image: grafana/grafana:latest | ||
volumes: | ||
- ./grafana.ini:/etc/grafana/grafana.ini | ||
- ./datasource.yaml:/etc/grafana/provisioning/datasources/datasource.yaml | ||
environment: | ||
GF_INSTALL_PLUGINS: grafana-clickhouse-datasource,vertamedia-clickhouse-datasource | ||
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: vertamedia-clickhouse-datasource | ||
ports: | ||
- "3000:3000" | ||
networks: | ||
- otel-clickhouse | ||
|
||
# Log generator | ||
flog: | ||
image: mingrammer/flog:0.4.3 | ||
# Output fake log in JSON format | ||
command: [ "--format=json", "--loop", "--delay=0.0001ms"] | ||
networks: | ||
- otel-clickhouse | ||
depends_on: | ||
- otel-collector | ||
logging: | ||
driver: fluentd | ||
options: | ||
mode: non-blocking | ||
# Allow time for otel-collector to spin up, then forward fluentd logs to the fluentforwarder receiver. | ||
fluentd-async-connect: "true" | ||
# Use nanosecond precision | ||
fluentd-sub-second-precision: "true" | ||
stop_signal: SIGKILL |
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,7 @@ | ||
[auth] | ||
disable_login_form = true | ||
|
||
[auth.anonymous] | ||
enabled = true | ||
org_name = Main Org. | ||
org_role = Admin |
39 changes: 39 additions & 0 deletions
39
exporter/clickhouseexporter/example/otel-collector-config.yml
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,39 @@ | ||
receivers: | ||
fluentforward: | ||
endpoint: 0.0.0.0:24224 | ||
|
||
processors: | ||
batch: | ||
send_batch_size: 100000 | ||
timeout: 2s | ||
memory_limiter: | ||
check_interval: 2s | ||
limit_mib: 1800 | ||
spike_limit_mib: 500 | ||
|
||
exporters: | ||
clickhouse: | ||
dsn: tcp://clickhouse:9000?database=default | ||
ttl_days: 3 | ||
timeout: 5s | ||
sending_queue: | ||
queue_size: 100 | ||
retry_on_failure: | ||
enabled: true | ||
initial_interval: 5s | ||
max_interval: 30s | ||
max_elapsed_time: 300s | ||
extensions: | ||
health_check: | ||
pprof: | ||
zpages: | ||
memory_ballast: | ||
size_mib: 1000 | ||
|
||
service: | ||
extensions: [pprof, zpages, health_check] | ||
pipelines: | ||
logs: | ||
receivers: [ fluentforward ] | ||
processors: [ memory_limiter, batch ] | ||
exporters: [ clickhouse ] |
Oops, something went wrong.