Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add global telemetry #724

Merged
merged 14 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/testing-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:

- id: count_tests
run: |
data=$(sudo go test -timeout 360s -v ./workers ./dnsutils ./transformers ./pkgconfig ./pkginit ././ 2>&1 | grep -c RUN)
data=$(sudo go test -timeout 360s -v ./workers ./dnsutils ./transformers ./pkgconfig ./pkginit ./telemetry ././ 2>&1 | grep -c RUN)
echo "Count of Tests: $data"
echo "data=$data" >> $GITHUB_OUTPUT

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ USER dnscollector
COPY --from=builder /build/go-dnscollector /bin/go-dnscollector
COPY --from=builder /build/docker-config.yml ./etc/dnscollector/config.yml

EXPOSE 6000/tcp 8080/tcp
EXPOSE 6000/tcp 8080/tcp 9165/tcp

ENTRYPOINT ["/bin/go-dnscollector"]

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tests: check-go
@go test ./pkgconfig/ -race -cover -v
@go test ./pkginit/ -race -cover -v
@go test ./netutils/ -race -cover -v
@go test ./telemetry/ -race -cover -v
@go test -timeout 90s ./transformers/ -race -cover -v
@go test -timeout 180s ./workers/ -race -cover -v

Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p align="center">
<img src="https://goreportcard.com/badge/github.com/dmachard/go-dns-collector" alt="Go Report"/>
<img src="https://img.shields.io/badge/go%20version-min%201.21-green" alt="Go version"/>
<img src="https://img.shields.io/badge/go%20tests-437-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20tests-439-green" alt="Go tests"/>
<img src="https://img.shields.io/badge/go%20bench-20-green" alt="Go bench"/>
<img src="https://img.shields.io/badge/go%20lines-29859-green" alt="Go lines"/>
<img src="https://img.shields.io/badge/go%20lines-30720-green" alt="Go lines"/>
</p>

<p align="center">
Expand Down Expand Up @@ -115,6 +115,17 @@ The [`_integration`](./docs/_integration) folder contains DNS-collector `configu
- [Elasticsearch](./docs/_integration/elasticsearch/README.md)
- [Kafka](./docs/_integration/kafka/README.md)

## Telemetry

Performance metrics are available to evaluate the efficiency of your pipelines. These metrics allow you to track:
- The number of incoming and outgoing packets processed by each worker
- The number of packets matching the policies applied (forwarded, dropped)
- The number of "discarded" packets
- Memory consumption
- CPU consumption

A [build-in](./docs/dashboards/grafana_exporter.json) dashboard is available for monitoring these metrics.

## Performance

Tuning may be necessary to deal with a large traffic loads.
Expand Down
16 changes: 15 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ global:
text-format-delimiter: " "
text-format-boundary: "\""
pid-file: ""
worker:
interval-monitor: 10
telemetry:
enabled: true
web-path: "/metrics"
web-listen: ":9165"
prometheus-prefix: "dnscollector_exporter"
tls-support: false
tls-cert-file: ""
tls-key-file: ""
client-ca-file: ""
basic-auth-enable: false
basic-auth-login: admin
basic-auth-pwd: changeme

################################################
# Pipelining configuration
Expand All @@ -27,7 +41,7 @@ pipelines:
qname-lowercase: true
routing-policy:
forward: [ console ]
dropped: []
dropped: [ ]

- name: console
stdout:
Expand Down
30 changes: 28 additions & 2 deletions dnscollector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"os"
"os/signal"
Expand All @@ -12,6 +13,7 @@ import (

"github.com/dmachard/go-dnscollector/pkgconfig"
"github.com/dmachard/go-dnscollector/pkginit"
"github.com/dmachard/go-dnscollector/telemetry"
"github.com/dmachard/go-dnscollector/workers"
"github.com/dmachard/go-logger"
"github.com/natefinch/lumberjack"
Expand Down Expand Up @@ -150,6 +152,12 @@ func main() {
InitLogger(logger, config)
logger.Info("main - version=%s revision=%s", version.Version, version.Revision)

// // telemetry
if config.Global.Telemetry.Enabled {
logger.Info("main - telemetry enabled on local address: %s", config.Global.Telemetry.WebListen)
}
promServer, metrics, errTelemetry := telemetry.InitTelemetryServer(config, logger)

// init active collectors and loggers
mapLoggers := make(map[string]workers.Worker)
mapCollectors := make(map[string]workers.Worker)
Expand All @@ -164,8 +172,8 @@ func main() {

// or pipeline ?
if pkginit.IsPipelinesEnabled(config) {
logger.Info("main - running in pipelines mode")
err := pkginit.InitPipelines(mapLoggers, mapCollectors, config, logger)
logger.Info("main - running in pipeline mode")
err := pkginit.InitPipelines(mapLoggers, mapCollectors, config, logger, metrics)
if err != nil {
logger.Error("main - %s", err.Error())
removePIDFile(config)
Expand All @@ -183,6 +191,11 @@ func main() {
go func() {
for {
select {
case err := <-errTelemetry:
logger.Error("main - unable to start telemetry: %v", err)
removePIDFile(config)
os.Exit(1)

case <-sigHUP:
logger.Warning("main - SIGHUP received")

Expand All @@ -205,6 +218,19 @@ func main() {

case <-sigTerm:
logger.Warning("main - exiting...")

// gracefully shutdown the HTTP server
if config.Global.Telemetry.Enabled {
logger.Info("main - telemetry is stopping")
metrics.Stop()

if err := promServer.Shutdown(context.Background()); err != nil {
logger.Error("main - telemetry error shutting down http server - %s", err.Error())
}

}

// and stop all workers
for _, c := range mapCollectors {
c.Stop()
}
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ services:
ports:
- "6000:6000/tcp"
- "8080:8080/tcp"
- "9165:9165/tcp"
restart: always
4 changes: 2 additions & 2 deletions docs/_examples/use-case-24.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pipelines:
dns.qtype: "TXT"
transforms:
atags:
tags: [ "TAG:TXT-QUERIES" ]
add-tags: [ "TAG:TXT-QUERIES" ]
routing-policy:
forward: [ apple-txt, all-txt ]

Expand All @@ -51,7 +51,7 @@ pipelines:
dns.qname: "^*.apple.com$"
transforms:
atags:
tags: [ "TXT:apple" ]
add-tags: [ "TXT:apple" ]
routing-policy:
forward: [ outputfile-apple ]

Expand Down
26 changes: 24 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ You can find the global settings below
- [Custom text format](#custom-text-format)
- [Server identity](#server-identity)
- [Pid file](#pid-file)
- [Telemetry](#telemetry)

### Trace

Expand Down Expand Up @@ -127,9 +128,30 @@ Output example:

### Pid file

Set path to create pid file.
Set path to create DNS-collector PID.
By default, this settings is empty.

```yaml
global:
pid-file: "/path/to/your/pidfile.pid"
```
```

### Telemetry

Enable and configure telemetry

```yaml
global:
telemetry:
enabled: true
web-path: "/metrics"
web-listen: ":9165"
prometheus-prefix: "dnscollector_exporter"
tls-support: false
tls-cert-file: ""
tls-key-file: ""
client-ca-file: ""
basic-auth-enable: false
basic-auth-login: admin
basic-auth-pwd: changeme
```
Loading
Loading