From f259bcd9a0b03c95b76d6b41940cdc8a3bf13478 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Mon, 8 Jul 2024 17:38:01 +0300 Subject: [PATCH] Pull request 59: 1-proxy-logs Closes #1. Squashed commit of the following: commit cd2285eeb8be222c078a90bddcc22449273dc8e3 Author: Ainar Garipov Date: Fri Jul 5 16:22:19 2024 +0300 dnssvc: imp docs commit 97c1caaa40388f2e9cd7526625fe1131be9b8618 Author: Ainar Garipov Date: Fri Jul 5 16:19:39 2024 +0300 cmd: rm more commit c8a360a3ab4086786ea52908151597acff32eed3 Author: Ainar Garipov Date: Fri Jul 5 15:42:24 2024 +0300 dnssvc: typo commit a0a7b73508523005e45be408c805cb3719273d8a Author: Ainar Garipov Date: Fri Jul 5 15:31:48 2024 +0300 all: fix bamboo commit 5c9118caf400d54d2b3de35de8682b13130c01f8 Author: Ainar Garipov Date: Fri Jul 5 15:22:15 2024 +0300 all: try fixing bamboo commit 4084a38f75c4ccec6b7a1947f718565789638bb8 Author: Ainar Garipov Date: Fri Jul 5 15:15:54 2024 +0300 all: imp logs; mv docs --- CHANGELOG.md | 5 + README.md | 9 +- bamboo-specs/bamboo.yaml | 41 +---- doc/configuration.md | 270 --------------------------------- doc/environment.md | 92 ----------- go.mod | 12 +- go.sum | 24 +-- internal/cmd/cmd.go | 4 +- internal/cmd/dns.go | 4 +- internal/cmd/program.go | 24 +-- internal/dnssvc/config.go | 26 ++-- internal/dnssvc/dnssvc.go | 13 +- internal/dnssvc/dnssvc_test.go | 2 + internal/tools/go.mod | 2 +- internal/tools/go.sum | 4 +- scripts/make/go-lint.sh | 16 +- scripts/make/txt-lint.sh | 12 -- 17 files changed, 81 insertions(+), 479 deletions(-) delete mode 100644 doc/configuration.md delete mode 100644 doc/environment.md diff --git a/CHANGELOG.md b/CHANGELOG.md index 795b009..682fae8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,11 @@ NOTE: Add new changes BELOW THIS COMMENT. - Path to the executable is now validated when the application installs itself as a `launchd` service on macOS ([#2]). +### Fixed + +- DNS proxy logs being written to `stderr` instead of `log.output` ([#1]). + +[#1]: https://github.com/AdguardTeam/AdGuardDNSClient/issues/1 [#2]: https://github.com/AdguardTeam/AdGuardDNSClient/issues/2 [go-1.22.5]: https://groups.google.com/g/golang-announce/c/gyb7aM1C9H4 diff --git a/README.md b/README.md index b315f90..b1e87e9 100644 --- a/README.md +++ b/README.md @@ -106,8 +106,7 @@ For building packages, you might need additional tools, such as GnuPG, MSI Tools ## Command-line options -Each option overrides the corresponding value provided by the configuration file -and the environment. +Each option overrides the corresponding value provided by the configuration file and the environment. ### Help @@ -134,10 +133,10 @@ Option `--version` makes AdGuard DNS Client print out the version of the `AdGuar ## Configuration -The YAML configuration file is described in the [`doc/configuration.md`] file, and there is also a sample configuration file `config.dist.yaml`. Some configuration parameters can also be overridden using the environment, see [`doc/environment.md`]. +The YAML configuration file is described in [its own article][conf], and there is also a sample configuration file `config.dist.yaml`. Some configuration parameters can also be overridden using the [environment][env]. -[`doc/configuration.md`]: doc/configuration.md -[`doc/environment.md`]: doc/environment.md +[conf]: https://adguard-dns.io/kb/dns-client/configuration/ +[env]: https://adguard-dns.io/kb/dns-client/environment/ ## Exit codes diff --git a/bamboo-specs/bamboo.yaml b/bamboo-specs/bamboo.yaml index 9f3e5b7..8275a0e 100644 --- a/bamboo-specs/bamboo.yaml +++ b/bamboo-specs/bamboo.yaml @@ -12,12 +12,6 @@ 'channel': 'development' 'stages': -- - 'Skip': - 'manual': false - 'final': false - 'jobs': - - 'Skip' - 'Lint': 'manual': false @@ -44,32 +38,6 @@ 'jobs': - 'Publish' -# The Skip stage terminates the plan execution prematurely if the main -# repository has no changes. This is needed to avoid builds triggered by -# changes in the linked repositories, e.g. bamboo-deploy-publisher. -# -# TODO(e.burkov): Remove this crutch, when the Bamboo version will support such -# a configuration for triggers via YAML specs, see -# https://docs.atlassian.com/bamboo-specs-docs/8.2.0/specs.html?yaml#triggering-selected-repositories. -'Skip': - 'key': 'SKIP' - 'tasks': - - - 'script': - - |- - #!/bin/sh - - set -e -f -u -x - - if [ "${bamboo.planRepository.revision}" = "${bamboo.planRepository.previousRevision}" ] - then - echo "aborting plan due to absent changes" - - exit 0 - fi - 'requirements': - - 'adg-docker': 'true' - 'Lint': 'docker': 'image': '${bamboo.dockerGo}' @@ -374,6 +342,10 @@ ../../bamboo-deploy-publisher/deploy.sh\ adguarddns-client-github +# TODO(e.burkov): Limit repositories when the Bamboo version will support such +# configuration for triggers via YAML specs. +# +# See https://docs.atlassian.com/bamboo-specs-docs/8.2.0/specs.html?yaml#triggering-selected-repositories. 'branches': 'create': 'for-pull-request' 'delete': @@ -442,11 +414,6 @@ # All the other branches, including master. '^.*': 'stages': - - 'Skip': - 'manual': false - 'final': false - 'jobs': - - 'Skip' - 'Lint': 'manual': false 'final': false diff --git a/doc/configuration.md b/doc/configuration.md deleted file mode 100644 index f212bfc..0000000 --- a/doc/configuration.md +++ /dev/null @@ -1,270 +0,0 @@ - # AdGuard DNS Client configuration file - -> [!WARNING] -> This is a temporary document. The final version will be posted to the [AdGuard DNS Knowledge Base][kb]. - -[kb]: https://adguard-dns.io/kb/ - -See file [`config.dist.yml`][dist] for a full example of a [YAML][yaml] -configuration file with comments. - -## Contents - - * [DNS](#dns) - * [Cache](#dns-cache) - * [Server](#dns-server) - * [Bootstrap](#dns-bootstrap) - * [Upstream](#dns-upstream) - * [Fallback](#dns-fallback) - * [Debugging](#debug) - * [Logging](#log) - -[dist]: ../config.dist.yml -[yaml]: https://yaml.org/ - - - -## DNS - -The `dns` object configures the behavior of DNS server. It has the following -properties: - - ### Cache - -The `cache` object configures caching the results of querying DNS. It has the -following properties: - - * `enabled`: - Whether or not the DNS results should be cached. - - **Example:** `true`. - - * `size`: - The maximum size of the DNS results cache as human-readable data size. It - must be greater than zero if [`enabled`](#dns-cache-enabled) is `true`. - - **Example:** `128MB`. - - * `client_size`: - The maximum size of the DNS results cache for each configured client’s - address or subnetwork as human-readable data size. It must be greater than - zero if [`enabled`](#dns-cache-enabled) is `true`. - - **Example:** `4MB`. - - - - ### Server - -The `server` object configures the handling of incoming requests. It has the -following properties: - - * `listen_addresses`: - The set of addresses with ports to listen on. - - **Property example:** - - ```yaml - 'listen_addresses': - - address: '127.0.0.1:53' - - address: '[::1]:53' - ``` - - - - ### Bootstrap - -The `bootstrap` object configures the resolving of [upstream](#dns-upstream) -servers addresses. It has the following properties: - - * `servers`: - The list of servers to use for resolving [upstream](#dns-upstream) servers - hostnames. - - **Property example:** - - ```yaml - 'servers': - - address: '8.8.8.8:53' - - address: '192.168.1.1:53' - ``` - - * `timeout`: - The timeout for bootstrap DNS requests as a human-readable duration. - - **Example:** `2s`. - - - - ### Upstream - -The `upstream` object configures the actual resolving of requests. It has the -following properties: - - - * `groups`: - The set of upstream servers keyed by the group’s name. It has the following - fields: - - * `address`: - The upstream server’s address. - - **Example:** `'8.8.8.8:53'`. - - * `match`: - The list of criteria to match the request against. Each entry may - contain the following properties: - - * `question_domain`: - The domain or a suffix of the domain that the set of upstream - servers should be used to resolve. - - **Example:** `'mycompany.local'`. - - * `client`: - The client’s address or a subnet of the client’s address that the - set of upstream servers should be used to resolve requests from. It - must have no significant bits outside of the subnet mask. - - **Example:** `'192.0.2.0/24'`. - - Note, that properties specified within a single entry are combined with - a logical *AND*. Entries are combined with a logical *OR*. - - **Property example:** - - ```yaml - 'match': - - question_domain: 'mycompany.local' - client: '192.168.1.0/24' - - question_domain: 'mycompany.external' - - client: '1.2.3.4' - ``` - - Note that `groups` should contain at least a single entry named `default`, - and optionally a single entry named `private`, both should have no `match` - property. - - The `default` group will be used when there are no matches among other - groups. - - The `private` group will be used to resolve the PTR requests for the private - IP addresses. Such queries will be answered with `NXDOMAIN` if no `private` - group is defined. - - * `timeout`: - The timeout for upstream DNS requests as a human-readable duration. - - **Example:** `2s`. - - - - ### Fallback - -The `fallback` object configures the behavior of DNS server on failures. It has -the following properties: - - * `servers`: - The list of servers to use after the actual [upstream](#dns-upstream) failed - to respond. - - **Property example:** - - ```yaml - 'servers': - - address: 'tls://94.140.14.140' - ``` - - * `timeout`: - The timeout for fallback DNS requests as a human-readable duration. - - **Example:** `2s`. - - - -## Debugging - -The `debug` object configures the debugging features. It has the following -properties: - - ### `pprof` - -The `pprof` object configures the [`pprof`][pkg-pprof] HTTP handlers. It has -the following properties: - - * `port`: - The port to listen on for debug HTTP requests on localhost. - - **Example:** `6060`. - - * `enabled`: - Whether or not the debug profiling is enabled. - - **Example:** `true`. - -[pkg-pprof]: https://golang.org/pkg/net/http/pprof - - - -## Logging - -> [!NOTE] -> In its current state, the log system is only intended for debugging startup errors. - -The `log` object configures the logging. It has the following properties: - - * `output`: - The output to which logs are written. - - > [!NOTE] - > Log entries written to the system log are in text format and use the system timestamp. - - > [!NOTE] - > If `log.format` is set to `adguard_legacy`, output is set to `stderr`. - - Possible values: - - * `syslog` means that the platform-specific system log is used, which is - syslog for Linux and Event Log for Windows. - - * `stdout` for standard output stream. - - * `stderr` for standard error stream. - - * Absolute path to the log file. - - **Example:** `/home/user/logs`. - - **Example:** `C:\Users\user\logs.txt`. - - **Example:** `syslog`. - - * `format`: - Specifies format of the log entries. - - > [!NOTE] - > If `log.format` is set to `adguard_legacy`, output is set to `stderr`. - - Possible values: - - * `adguard_legacy`; - * `default`; - * `json`; - * `jsonhybrid`; - * `text`. - - **Example:** `default`. - - - - * `timestamp`: - If the log entries should contain timestamp. - - **Example:** `false`. - - * `verbose`: - If the log should be more informative. - - **Example:** `false`. diff --git a/doc/environment.md b/doc/environment.md deleted file mode 100644 index 5c0c0ec..0000000 --- a/doc/environment.md +++ /dev/null @@ -1,92 +0,0 @@ -# AdGuard DNS Client environment configuration - -> [!WARNING] -> This is a temporary document. The final version will be posted to the [AdGuard DNS Knowledge Base][kb]. - -[kb]: https://adguard-dns.io/kb/ - -AdGuard DNS Client uses [environment variables][wiki-env] to store some of the configuration. All other configuration is stored in the [configuration file][conf]. - -## Contents - -- [`LOG_OUTPUT`](#LOG_OUTPUT) -- [`LOG_FORMAT`](#LOG_FORMAT) -- [`LOG_TIMESTAMP`](#LOG_TIMESTAMP) -- [`VERBOSE`](#VERBOSE) - -[conf]: configuration.md -[wiki-env]: https://en.wikipedia.org/wiki/Environment_variable - -> [!NOTE] -> In its current state, the log system is only intended for debugging startup errors. - -## `LOG_OUTPUT` - -The log destination, must be an absolute path to the file or one of the special values. - -> [!NOTE] -> If `LOG_FORMAT` is set to `adguard_legacy`, output is set to `stderr`. - -- `syslog` means that the platform-specific system log is used, which is syslog for Linux and Event Log for Windows. - - > [!NOTE] - > Log entries written to the system log are in text format and use the system timestamp. - -- `stdout` for standard output stream. - -- `stderr` for standard error stream. - -- Absolute path to the log file. - - **Example:** `/home/user/logs`. - - **Example:** `C:\Users\user\logs.txt`. - -This environment variable has priority over [log.output][conf-log-output] field from the configuration file. - -**Default:** **Unset.** - -[conf-log-output]: configuration.md#log-output - -## `LOG_FORMAT` - -The format for log entries. - -> [!NOTE] -> If `LOG_FORMAT` is set to `adguard_legacy`, output is set to `stderr`. - -- `adguard_legacy`; -- `default`; -- `json`; -- `json_hybrid`; -- `text`. - - - -This environment variable has priority over [log.format][conf-log-format] field from the configuration file. - -**Default:** **Unset.** - -[conf-log-format]: configuration.md#log-format - -## `LOG_TIMESTAMP` - -When set to `1`, log entries have a timestamp. When set to `0`, log entries don’t have it. - -This environment variable has priority over [log.timestamp][conf-log-timestamp] field from the configuration file. - -**Default:** **Unset.** - -[conf-log-timestamp]: configuration.md#log-timestamp - -## `VERBOSE` - -When set to `1`, enable verbose logging. When set to `0`, disable it. - -This environment variable has priority over [log.verbose][conf-log-verbose] field from the configuration file. - -**Default:** **Unset.** - -[conf-log-verbose]: configuration.md#log-verbose diff --git a/go.mod b/go.mod index 0596670..124c279 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/AdguardTeam/AdGuardDNSClient go 1.22.5 require ( - github.com/AdguardTeam/dnsproxy v0.71.2 + github.com/AdguardTeam/dnsproxy v0.72.0 github.com/AdguardTeam/golibs v0.24.1 github.com/c2h5oh/datasize v0.0.0-20231215233829-aa82cc1e6500 github.com/miekg/dns v1.1.61 github.com/stretchr/testify v1.9.0 - golang.org/x/sys v0.21.0 + golang.org/x/sys v0.22.0 gopkg.in/yaml.v3 v3.0.1 ) @@ -21,17 +21,17 @@ require ( github.com/bluele/gcache v0.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect - github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8 // indirect + github.com/google/pprof v0.0.0-20240625030939-27f56978b8b0 // indirect github.com/kardianos/service v1.2.2 github.com/onsi/ginkgo/v2 v2.19.0 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect - github.com/quic-go/quic-go v0.45.0 // indirect + github.com/quic-go/quic-go v0.45.1 // indirect go.uber.org/mock v0.4.0 // indirect - golang.org/x/crypto v0.24.0 // indirect + golang.org/x/crypto v0.25.0 // indirect golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect - golang.org/x/mod v0.18.0 // indirect + golang.org/x/mod v0.19.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/text v0.16.0 // indirect diff --git a/go.sum b/go.sum index 7824f33..092c273 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/AdguardTeam/dnsproxy v0.71.2 h1:dFG2wga4GDdj1eI3rU2wqjQ6QGQm9MjLRb5ZzyH3Vgg= -github.com/AdguardTeam/dnsproxy v0.71.2/go.mod h1:huI5zyWhlimHBhg0jt2CMinXzsEHymI+WlvxIfmfEGA= +github.com/AdguardTeam/dnsproxy v0.72.0 h1:Psn7uCMVR/dCx8Te2Iy05bWWRNArSBF9j38VXNtt6+4= +github.com/AdguardTeam/dnsproxy v0.72.0/go.mod h1:5ehzbfInAu07not4beAM+FlFPqntw18T1sQCK/kIQR8= github.com/AdguardTeam/golibs v0.24.1 h1:/ulkfm65wi33p72ybxiOt3lSdP0nr1GggSoaT4sHbns= github.com/AdguardTeam/golibs v0.24.1/go.mod h1:9/vJcYznW7RlmCT/Qzi8XNZGj+ZbWfHZJmEXKnRpCAU= github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY= @@ -24,8 +24,8 @@ github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1v github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8 h1:ASJ/LAqdCHOyMYI+dwNxn7Rd8FscNkMyTr1KZU1JI/M= -github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= +github.com/google/pprof v0.0.0-20240625030939-27f56978b8b0 h1:e+8XbKB6IMn8A4OAyZccO4pYfB3s7bt6azNIPE7AnPg= +github.com/google/pprof v0.0.0-20240625030939-27f56978b8b0/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= github.com/kardianos/service v1.2.2 h1:ZvePhAHfvo0A7Mftk/tEzqEZ7Q4lgnR8sGz4xu1YX60= github.com/kardianos/service v1.2.2/go.mod h1:CIMRFEJVL+0DS1a3Nx06NaMn4Dz63Ng6O7dl0qH0zVM= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -44,25 +44,25 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= -github.com/quic-go/quic-go v0.45.0 h1:OHmkQGM37luZITyTSu6ff03HP/2IrwDX1ZFiNEhSFUE= -github.com/quic-go/quic-go v0.45.0/go.mod h1:1dLehS7TIR64+vxGR70GDcatWTOtMX2PUtnKsjbTurI= +github.com/quic-go/quic-go v0.45.1 h1:tPfeYCk+uZHjmDRwHHQmvHRYL2t44ROTujLeFVBmjCA= +github.com/quic-go/quic-go v0.45.1/go.mod h1:1dLehS7TIR64+vxGR70GDcatWTOtMX2PUtnKsjbTurI= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU= go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc= -golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI= -golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM= +golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 h1:yixxcjnhBmY0nkL253HFVIm0JsFHwrHdT3Yh6szTnfY= golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8/go.mod h1:jj3sYF3dwk5D+ghuXyeI3r5MFf+NT2An6/9dOA95KSI= -golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= -golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= +golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ= golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index a716ed0..8c4bcf6 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -43,7 +43,7 @@ func Main() { conf: conf, done: make(chan struct{}), errCh: make(chan error), - log: l, + logger: l, logFile: logFile, } @@ -96,7 +96,7 @@ func check(ctx context.Context, prog *program, err error) { return } - prog.log.ErrorContext(ctx, "fatal error", slogutil.KeyError, err) + prog.logger.ErrorContext(ctx, "fatal error", slogutil.KeyError, err) prog.closeLogs() os.Exit(osutil.ExitCodeFailure) diff --git a/internal/cmd/dns.go b/internal/cmd/dns.go index f038567..61a7568 100644 --- a/internal/cmd/dns.go +++ b/internal/cmd/dns.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "log/slog" "net/netip" "github.com/AdguardTeam/AdGuardDNSClient/internal/dnssvc" @@ -56,8 +57,9 @@ func (c *dnsConfig) validate() (err error) { // toInternal converts the DNS configuration to the internal representation. c // must be valid. -func (c *dnsConfig) toInternal() (conf *dnssvc.Config) { +func (c *dnsConfig) toInternal(logger *slog.Logger) (conf *dnssvc.Config) { return &dnssvc.Config{ + Logger: logger, // TODO(e.burkov): Consider making configurable. PrivateSubnets: netutil.SubnetSetFunc(netutil.IsLocallyServed), Cache: c.Cache.toInternal(), diff --git a/internal/cmd/program.go b/internal/cmd/program.go index 7578c0e..824d6f8 100644 --- a/internal/cmd/program.go +++ b/internal/cmd/program.go @@ -9,7 +9,6 @@ import ( "github.com/AdguardTeam/AdGuardDNSClient/internal/dnssvc" "github.com/AdguardTeam/AdGuardDNSClient/internal/version" - "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/service" osservice "github.com/kardianos/service" @@ -23,7 +22,7 @@ type program struct { // conf is the parsed configuration to run the program. It appears nil on // any service action and must not be accessed. conf *configuration - log *slog.Logger + logger *slog.Logger logFile *os.File done chan struct{} errCh chan error @@ -39,18 +38,7 @@ const serviceProgramPrefix = "program" // Start implements the [osservice.Interface] interface for [*program]. func (prog *program) Start(_ osservice.Service) (err error) { ctx := context.Background() - l := prog.log.With(slogutil.KeyPrefix, serviceProgramPrefix) - - // Disable the dnsproxy logging for now, unless asked for debug output or - // using the "adguard_legacy" format. - // - // TODO(e.burkov): Use [log/slog] in [dnsproxy] and make it configurable. - isVerbose := l.Enabled(ctx, slog.LevelDebug) - if isVerbose { - log.SetLevel(log.DEBUG) - } else if _, ok := l.Handler().(*slogutil.AdGuardLegacyHandler); !ok { - log.SetLevel(log.OFF) - } + l := prog.logger.With(slogutil.KeyPrefix, serviceProgramPrefix) // TODO(a.garipov): Copy logs configuration from the WIP abt. slog. l.InfoContext( @@ -61,12 +49,12 @@ func (prog *program) Start(_ osservice.Service) (err error) { "branch", version.Branch(), "commit_time", version.CommitTime(), "race", version.RaceEnabled, - "verbose", isVerbose, + "verbose", l.Enabled(ctx, slog.LevelDebug), ) svcHdlr := newServiceHandler(prog.done, service.SignalHandlerShutdownTimeout) - dnsSvc, err := dnssvc.New(prog.conf.DNS.toInternal()) + dnsSvc, err := dnssvc.New(prog.conf.DNS.toInternal(prog.logger)) if err != nil { return fmt.Errorf("creating dns service: %w", err) } @@ -79,7 +67,7 @@ func (prog *program) Start(_ osservice.Service) (err error) { svcHdlr.add(dnsSvc) l.DebugContext(ctx, "dns service started") - go svcHdlr.handle(ctx, prog.log.With(slogutil.KeyPrefix, "service_handler"), prog.errCh) + go svcHdlr.handle(ctx, prog.logger.With(slogutil.KeyPrefix, "service_handler"), prog.errCh) return nil } @@ -105,7 +93,7 @@ func (prog *program) closeLogs() { } } - h := prog.log.Handler() + h := prog.logger.Handler() if c, ok := h.(io.Closer); ok { err := c.Close() if err != nil { diff --git a/internal/dnssvc/config.go b/internal/dnssvc/config.go index 0f68d24..c3ca15a 100644 --- a/internal/dnssvc/config.go +++ b/internal/dnssvc/config.go @@ -1,39 +1,39 @@ package dnssvc import ( + "log/slog" "net/netip" "github.com/AdguardTeam/golibs/netutil" ) -// Config is the configuration for [DNSService]. -// -// TODO(e.burkov): Add cache. +// Config is the configuration for [DNSService]. All fields must not be empty. type Config struct { + // Logger is used as the base logger for the DNS service. + Logger *slog.Logger + // PrivateSubnets is the set of IP networks considered private. The PTR // requests for ARPA domains considered private if the domain contains an IP // from one of the networks and the request came from the client within one - // of the networks. It must not be nil. + // of the networks. PrivateSubnets netutil.SubnetSet - // Cache is the configuration for the DNS results cache. It must not be - // nil. + // Cache is the configuration for the DNS results cache. Cache *CacheConfig - // Bootstrap describes bootstrapping DNS servers. It must not be nil. + // Bootstrap describes bootstrapping DNS servers. Bootstrap *BootstrapConfig - // Upstreams describes DNS upstream servers. It must not be nil. + // Upstreams describes DNS upstream servers. Upstreams *UpstreamConfig - // Fallbacks describes DNS fallback upstream servers. It must not be nil. + // Fallbacks describes DNS fallback upstream servers. Fallbacks *FallbackConfig - // ClientGetter is the function to get the client for a request. It must - // not be nil. + // ClientGetter is the function to get the client for a request. ClientGetter ClientGetter - // ListenAddrs is the list of served addresses. It must contain at least a - // single entry. + // ListenAddrs is the list of served addresses. It must contain at least + // one entry. ListenAddrs []netip.AddrPort } diff --git a/internal/dnssvc/dnssvc.go b/internal/dnssvc/dnssvc.go index f8097ba..1b9e15d 100644 --- a/internal/dnssvc/dnssvc.go +++ b/internal/dnssvc/dnssvc.go @@ -5,18 +5,23 @@ import ( "context" "fmt" "io" + "log/slog" "net" "net/netip" "github.com/AdguardTeam/dnsproxy/proxy" "github.com/AdguardTeam/dnsproxy/upstream" "github.com/AdguardTeam/golibs/errors" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/netutil" "github.com/AdguardTeam/golibs/service" ) // DNSService is a service that provides DNS handling functionality. type DNSService struct { + // logger is used as the base logger for the DNS service. + logger *slog.Logger + // proxy forwards DNS requests. proxy *proxy.Proxy @@ -50,6 +55,7 @@ func New(conf *Config) (svc *DNSService, err error) { } svc = &DNSService{ + logger: conf.Logger.With(slogutil.KeyPrefix, "dnssvc"), clientGetter: conf.ClientGetter, clients: newClientStorage(clients), } @@ -101,6 +107,8 @@ func newProxyConfig( } return &proxy.Config{ + Logger: conf.Logger.With(slogutil.KeyPrefix, "dnsproxy"), + UpstreamMode: proxy.UpstreamModeLoadBalance, UDPListenAddr: udp, TCPListenAddr: tcp, UpstreamConfig: general, @@ -133,13 +141,16 @@ var _ service.Interface = (*DNSService)(nil) // Start implements the [service.Interface] interface for *DNSService. func (svc *DNSService) Start(ctx context.Context) (err error) { + svc.logger.DebugContext(ctx, "starting") + return svc.proxy.Start(ctx) } // Shutdown implements the [service.Interface] interface for *DNSService. func (svc *DNSService) Shutdown(ctx context.Context) (err error) { - var errs []error + svc.logger.DebugContext(ctx, "shutting down") + var errs []error err = svc.proxy.Shutdown(ctx) if err != nil { errs = append(errs, fmt.Errorf("stopping proxy: %w", err)) diff --git a/internal/dnssvc/dnssvc_test.go b/internal/dnssvc/dnssvc_test.go index 0f8c116..2f2789b 100644 --- a/internal/dnssvc/dnssvc_test.go +++ b/internal/dnssvc/dnssvc_test.go @@ -10,6 +10,7 @@ import ( "github.com/AdguardTeam/AdGuardDNSClient/internal/agdc" "github.com/AdguardTeam/AdGuardDNSClient/internal/dnssvc" "github.com/AdguardTeam/dnsproxy/proxy" + "github.com/AdguardTeam/golibs/logutil/slogutil" "github.com/AdguardTeam/golibs/netutil" "github.com/AdguardTeam/golibs/testutil" "github.com/miekg/dns" @@ -180,6 +181,7 @@ func TestDNSService(t *testing.T) { // Create and start the service. svc, err := dnssvc.New(&dnssvc.Config{ + Logger: slogutil.NewDiscardLogger(), PrivateSubnets: privateNets, Bootstrap: &dnssvc.BootstrapConfig{}, Cache: &dnssvc.CacheConfig{ diff --git a/internal/tools/go.mod b/internal/tools/go.mod index 8a9ea30..cbc8a8a 100644 --- a/internal/tools/go.mod +++ b/internal/tools/go.mod @@ -30,6 +30,6 @@ require ( golang.org/x/mod v0.19.0 // indirect golang.org/x/sync v0.7.0 // indirect golang.org/x/sys v0.22.0 // indirect - golang.org/x/telemetry v0.0.0-20240703200001-5377abf9626c // indirect + golang.org/x/telemetry v0.0.0-20240704191351-af73eac657e1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/internal/tools/go.sum b/internal/tools/go.sum index 672a70e..7c5d593 100644 --- a/internal/tools/go.sum +++ b/internal/tools/go.sum @@ -95,8 +95,8 @@ golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220702020025-31831981b65f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/telemetry v0.0.0-20240703200001-5377abf9626c h1:RA2e/R39vjb71phnEiuAiHQXvBDQ0BhsJUrxiOisErU= -golang.org/x/telemetry v0.0.0-20240703200001-5377abf9626c/go.mod h1:n38mvGdgc4dA684EC4NwQwoPKSw4jyKw8/DgZHDA1Dk= +golang.org/x/telemetry v0.0.0-20240704191351-af73eac657e1 h1:BsQ49iG0DV5gj1qo45N0EjsbN62m02CHvfgHMjb7HCI= +golang.org/x/telemetry v0.0.0-20240704191351-af73eac657e1/go.mod h1:amNmu/SBSm2GAF3X+9U2C0epLocdh+r5Z+7oMYO5cLM= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/scripts/make/go-lint.sh b/scripts/make/go-lint.sh index 1e7bb3b..8171e67 100644 --- a/scripts/make/go-lint.sh +++ b/scripts/make/go-lint.sh @@ -3,7 +3,7 @@ # This comment is used to simplify checking local copies of the script. Bump # this number every time a significant change is made to this script. # -# AdGuard-Project-Version: 5 +# AdGuard-Project-Version: 6 verbose="${VERBOSE:-0}" readonly verbose @@ -51,23 +51,27 @@ set -f -u # # * Package unsafe is… unsafe. # +# * Package golang.org/x/exp/slices has been moved into stdlib. +# # * Package golang.org/x/net/context has been moved into stdlib. # # Currently, the only standard exception are files generated from protobuf # schemas, which use package reflect. If your project needs more exceptions, # add and document them. # -# TODO(a.garipov): Add deprecated packages golang.org/x/exp/maps and -# golang.org/x/exp/slices once all projects switch to Go 1.21. +# TODO(a.garipov): Add deprecated package golang.org/x/exp/maps once all +# projects switch to Go 1.23. blocklist_imports() { git grep\ -e '[[:space:]]"errors"$'\ + -e '[[:space:]]"github.com/AdguardTeam/golibs/log"$'\ + -e '[[:space:]]"golang.org/x/exp/slices"$'\ + -e '[[:space:]]"golang.org/x/net/context"$'\ -e '[[:space:]]"io/ioutil"$'\ -e '[[:space:]]"log"$'\ -e '[[:space:]]"reflect"$'\ -e '[[:space:]]"sort"$'\ -e '[[:space:]]"unsafe"$'\ - -e '[[:space:]]"golang.org/x/net/context"$'\ -n\ -- '*.go'\ ':!*.pb.go'\ @@ -132,7 +136,7 @@ run_linter -e gofumpt --extra -e -l . # TODO(a.garipov): golint is deprecated, find a suitable replacement. -run_linter "$GO" vet ./... +run_linter "${GO:-go}" vet ./... run_linter govulncheck ./... @@ -148,8 +152,6 @@ git ls-files -- 'Makefile' '*.conf' '*.go' '*.mod' '*.sh' '*.yaml' '*.yml'\ | xargs misspell --error\ | sed -e 's/^/misspell: /' -run_linter looppointer ./... - run_linter nilness ./... run_linter fieldalignment ./... diff --git a/scripts/make/txt-lint.sh b/scripts/make/txt-lint.sh index 988276a..8b56b5b 100644 --- a/scripts/make/txt-lint.sh +++ b/scripts/make/txt-lint.sh @@ -40,12 +40,6 @@ trailing_newlines() ( # NOTE: Adjust for your project. git ls-files\ ':!*.bmp'\ - ':!*.jpg'\ - ':!*.mmdb'\ - ':!*.png'\ - ':!*.tar.gz'\ - ':!*.webp'\ - ':!*.zip'\ | while read -r f do final_byte="$( tail -c -1 "$f" )" @@ -62,12 +56,6 @@ trailing_whitespace() { # NOTE: Adjust for your project. git ls-files\ ':!*.bmp'\ - ':!*.jpg'\ - ':!*.mmdb'\ - ':!*.png'\ - ':!*.tar.gz'\ - ':!*.webp'\ - ':!*.zip'\ | while read -r f do grep -e '[[:space:]]$' -n -- "$f"\