Skip to content

Commit

Permalink
Fix broken logstash UDP support (TykTechnologies#2141)
Browse files Browse the repository at this point in the history
This PR disables `gas` reconnection functionality when `"logstash_transport": "udp"` because it doesn't support `udp`.
 
Also, we need to fix doc here: https://tyk.io/docs/log-data/#a-name-aggregated-logs-with-logstash-a-aggregated-logs-with-logstash. It says `logstash_transport: The Logstash transport to use, should be "tcp".` but we support `udp` too. And, it would be easier for user if we give a logstash input configuration there like:

```
input {
	tcp {	
		port => 5044
		codec => json
	}
}
```
Fixes TykTechnologies#2136
  • Loading branch information
furkansenharputlu authored and buger committed Mar 1, 2019
1 parent 0971f70 commit 14ffe74
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ var (
const (
defReadTimeout = 120 * time.Second
defWriteTimeout = 120 * time.Second
appName = "tyk-gateway"
)

func getApiSpec(apiID string) *APISpec {
Expand Down Expand Up @@ -767,12 +768,25 @@ func setupLogger() {
if config.Global().UseLogstash {
mainLog.Debug("Enabling Logstash support")

conn, err := gas.Dial(config.Global().LogstashTransport, config.Global().LogstashNetworkAddr)
if err != nil {
log.Errorf("Error making connection for logstash hook: %v", err)
var hook *logstashHook.Hook
var err error
var conn net.Conn
if config.Global().LogstashTransport == "udp" {
mainLog.Debug("Connecting to Logstash with udp")
hook, err = logstashHook.NewHook(config.Global().LogstashTransport,
config.Global().LogstashNetworkAddr,
appName)
} else {
mainLog.Debugf("Connecting to Logstash with %s", config.Global().LogstashTransport)
conn, err = gas.Dial(config.Global().LogstashTransport, config.Global().LogstashNetworkAddr)
if err == nil {
hook, err = logstashHook.NewHookWithConn(conn, appName)
}
}
hook, err := logstashHook.NewHookWithConn(conn, "tyk-gateway")
if err == nil {

if err != nil {
log.Errorf("Error making connection for logstash: %v", err)
} else {
log.Hooks.Add(hook)
rawLog.Hooks.Add(hook)
mainLog.Debug("Logstash hook active")
Expand Down

0 comments on commit 14ffe74

Please sign in to comment.