Skip to content

Commit

Permalink
Fixing log level and wildcard features (#72)
Browse files Browse the repository at this point in the history
* Fixing log level that stopped of work after **2.5.0**
* Fixing and increasing docs development instructions
* Fixing wildcard resolution were not solving main domain to docker container, just the subdomains
  • Loading branch information
mageddo authored May 31, 2018
1 parent 0f03418 commit c454983
Show file tree
Hide file tree
Showing 22 changed files with 269 additions and 137 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<a href="https://travis-ci.org/mageddo/dns-proxy-server"><img src="https://travis-ci.org/mageddo/dns-proxy-server.svg?branch=master" alt="Build Status"></img></a>
</p>

### Features
### [Features](http://mageddo.github.io/dns-proxy-server/docs/features)
* [Take a look at features for more details](http://mageddo.github.io/dns-proxy-server/docs/features)

Dns-proxy-server is a end user(developers, Server Administrators) DNS server tool to develop systems with docker solving docker containers hostnames:

* Solve hostnames from local configuration database
* Solve hostnames from docker containers using docker **hostname** option or **HOSTNAMES** env
* Solve hostnames from a list of configured DNS servers(as a proxy) if no answer of two above
* Solve hostnames using wildcards
> If you register a hostname with `.` at start, then all subdomains will solve to that container/local storage entry
* [Solve hostnames using wildcards](http://mageddo.github.io/dns-proxy-server/docs/features#Solve-hostnames-using-wildcards)
* [Graphic interface to manage it](http:/127.0.0.1:5380/static/)
* List and edit DNS local entries

Expand Down Expand Up @@ -128,14 +128,14 @@ Start the server at [custom port](#configure-your-dns) and solving from it
-log-file string
Log to file instead of console, (true=log to default log file, /tmp/log.log=log to custom log location) (default "console")
-log-level string
Log Level CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG (default "DEBUG")
Log Level ERROR, WARNING, INFO, DEBUG (default "DEBUG")
-server-port int
The DNS server to start into (default 53)
-service string
Setup as service, starting with machine at boot
docker = start as docker service,
normal = start as normal service,
uninstall = uninstall the service from machine
uninstall = uninstall the service from machine
-service-publish-web-port
Publish web port when running as service in docker mode (default true)
-tsig string
Expand Down Expand Up @@ -186,8 +186,8 @@ if you don't want this service anymore


### Rest API

* [Latest API documentation](https://github.com/mageddo/dns-proxy-server/tree/master/docs/api) of DNS proxy server APIs
* [Latest API features](http://mageddo.github.io/dns-proxy-server/docs/api/) of DNS proxy server APIs

### Developing
Take a look at the [wiki](docs) for more details of how develop at this project

Take a look at the [wiki](docs/developing) for more details of how develop at this project
5 changes: 5 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 2.5.2
* Fixing log level that stopped of work after **2.5.0**
* Fixing and increasing docs development instructions
* Fixing wildcard resolution were not solving main domain to docker container, just the subdomains

### 2.5.1
* Fixing ping slowness, takes more than 10 seconds to respond

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.5.2
7 changes: 6 additions & 1 deletion builder
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ case $1 in

rm -rf build/
mkdir -p build/
go test -v -race -cover -ldflags "-X github.com/mageddo/dns-proxy-server/flags.version=test" ./.../

echo "> Testing ..."
go test -race -cover -ldflags "-X github.com/mageddo/dns-proxy-server/flags.version=test" ./.../
echo "> Tests completed"

echo "> Building..."
go build -v -o build/dns-proxy-server -ldflags "-X github.com/mageddo/dns-proxy-server/flags.version=$APP_VERSION"
cp -r static build/
cd build/
Expand Down
25 changes: 20 additions & 5 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"github.com/mageddo/dns-proxy-server/utils/env"
"strings"
"github.com/mageddo/go-logging"
)

func CpuProfile() string {
Expand Down Expand Up @@ -49,17 +50,31 @@ func getConf() (*local.LocalConfiguration, error) {
return local.LoadConfiguration()
}

func LogLevel() string {
func LogLevel() int {
if lvl := os.Getenv(env.MG_LOG_LEVEL); lvl != "" {
return lvl
return logKeyToSyslogCode(lvl)
}

if conf, _ := getConf(); conf != nil && conf.LogLevel != "" {
return conf.LogLevel
return logKeyToSyslogCode(conf.LogLevel)
}
return flags.LogLevel()
return logKeyToSyslogCode(flags.LogLevel())
}

func logKeyToSyslogCode(key string) int {
switch strings.ToUpper(key) {
case "DEBUG":
return logging.DEBUG
case "INFO":
return logging.INFO
case "WARNING":
return logging.WARNING
case "ERROR":
return logging.ERROR
}
panic("Unknow log level: " + key)
}


func LogFile() string {
f := os.Getenv(env.MG_LOG_FILE)
if conf, _ := getConf(); f == "" && conf != nil && conf.LogFile != "" {
Expand Down
7 changes: 4 additions & 3 deletions conf/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/mageddo/dns-proxy-server/utils"
"flag"
"github.com/mageddo/dns-proxy-server/utils/env"
"github.com/mageddo/go-logging"
)

func TestDefaultFlagValues(t *testing.T) {
Expand Down Expand Up @@ -40,7 +41,7 @@ func TestFlagValuesFromConf(t *testing.T) {


func TestLogLevel_DefaultValue(t *testing.T) {
assert.Equal(t, "DEBUG", LogLevel())
assert.Equal(t, logging.DEBUG, LogLevel())
}

func TestLogLevel_ReadFromConfig(t *testing.T) {
Expand All @@ -55,7 +56,7 @@ func TestLogLevel_ReadFromConfig(t *testing.T) {
level := LogLevel()

// assert
assert.Equal(t, "INFO", level)
assert.Equal(t, logging.INFO, level)

os.Remove(local.GetConfPath())
}
Expand All @@ -69,7 +70,7 @@ func TestLogLevel_ReadFromEnv(t *testing.T) {
level := LogLevel()

// assert
assert.Equal(t, "WARNING", level)
assert.Equal(t, logging.WARNING, level)

}

Expand Down
7 changes: 1 addition & 6 deletions dns.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
_ "github.com/mageddo/dns-proxy-server/log"
_ "github.com/mageddo/dns-proxy-server/controller"
"github.com/mageddo/dns-proxy-server/log"
"fmt"
"os"
"runtime/pprof"
Expand All @@ -24,11 +24,6 @@ import (
"context"
)

func init(){
// TODO unavailable log.SetLevel(conf.LogLevel())
log.SetOutput(conf.LogFile())
}

func handleQuestion(respWriter dns.ResponseWriter, reqMsg *dns.Msg) {

defer func() {
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
# Base Image to build project
compiler-dps:
image: golang:1.9
container_name: docker-dns-gocompiler
container_name: gocompiler-dps
working_dir: /app/src/github.com/mageddo/dns-proxy-server
volumes:
- $PWD:/app/src/github.com/mageddo/dns-proxy-server
Expand All @@ -20,7 +20,6 @@ services:

# Run from docker image
prod-dps:
container_name: dns-proxy-server
image: defreitas/dns-proxy-server:2.5.1
hostname: dns.mageddo
volumes:
Expand Down
28 changes: 0 additions & 28 deletions docs/Compiling-the-project-from-source.md

This file was deleted.

52 changes: 0 additions & 52 deletions docs/Features.md

This file was deleted.

5 changes: 2 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
* [Building from source with docker](Compiling-the-project-from-source.md)
* [Developing with docker](Developing-at-the-project.md)
* [Generate Version](README.md)
* [Features](features.md)
* [API Documentation](api)
* [Developing](developing)
39 changes: 39 additions & 0 deletions docs/developing/Compiling-the-project-from-source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
### Building from source with docker

**DPS** uses docker to simplify the compile process


Generate the binaries

```bash
$ docker-compose up prod-build-binary-dps
Starting docker-dns-server-compiler
Attaching to docker-dns-server-compiler
docker-dns-server-compiler | ok github.com/mageddo/dns-proxy-server/conf 0.008s
docker-dns-server-compiler | ? github.com/mageddo/dns-proxy-server/controller [no test files]
...
docker-dns-server-compiler | github.com/mageddo/dns-proxy-server/flags
...
docker-dns-server-compiler | _/app/src
docker-dns-server-compiler exited with code 0
```

Then binaries mus be available at **build** folder

```
$ ls build/
dns-proxy-server dns-proxy-server-2.5.1.tgz static
```

If you want you can build the docker image

```
$ docker-compose build prod-build-image-dps && docker-compose up prod-dps
```

### Used tecnologies

* Docker
* Docker Compose
* Git
* Golang 1.9
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

Setup the environment

$ docker-compose -d compiler-dps up
$ docker exec -it gocompiler bash
$ docker-compose up -d compiler-dps && docker exec -it gocompiler-dps bash

Running the application

Expand Down
File renamed without changes.
Loading

0 comments on commit c454983

Please sign in to comment.