Skip to content

Commit

Permalink
Remove unused user correlation id feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Dino Omanovic committed Jul 10, 2017
1 parent 600f57b commit 64f4b59
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 29 deletions.
14 changes: 1 addition & 13 deletions logging/correlation_id.go
@@ -1,7 +1,6 @@
package logging

import (
"github.com/tarent/lib-compose/util"
"math/rand"
"net/http"
"time"
Expand All @@ -14,7 +13,6 @@ func init() {
}

var CorrelationIdHeader = "X-Correlation-Id"
var UserCorrelationCookie = ""

// EnsureCorrelationId returns the correlation from of the request.
// If the request does not have a correlation id, one will be generated and set to the request.
Expand All @@ -38,14 +36,4 @@ func randStringBytes(n int) string {
b[i] = letterBytes[rand.Intn(len(letterBytes))]
}
return string(b)
}

// GetCorrelationId returns the users correlation id of the headers.
func GetUserCorrelationId(h http.Header) string {
if UserCorrelationCookie != "" {
if value, found := util.ReadCookieValue(h, UserCorrelationCookie); found {
return value
}
}
return ""
}
}
5 changes: 0 additions & 5 deletions logging/logger.go
Expand Up @@ -236,11 +236,6 @@ func setCorrelationIds(fields logrus.Fields, h http.Header) {
if correlationId != "" {
fields["correlation_id"] = correlationId
}

userCorrelationId := GetUserCorrelationId(h)
if userCorrelationId != "" {
fields["user_correlation_id"] = userCorrelationId
}
}

func contains(s []string, e string) bool {
Expand Down
13 changes: 2 additions & 11 deletions logging/logger_test.go
Expand Up @@ -23,7 +23,6 @@ type logReccord struct {
Proto string `json:"proto"`
Duration int `json:"duration"`
ResponseStatus int `json:"response_status"`
UserCorrelationId string `json:"user_correlation_id"`
Cookies map[string]string `json:"cookies"`
Error string `json:"error"`
Message string `json:"message"`
Expand Down Expand Up @@ -57,13 +56,12 @@ func Test_Logger_Call(t *testing.T) {
b := bytes.NewBuffer(nil)
Logger.Out = b
AccessLogCookiesBlacklist = []string{"ignore", "user_id"}
UserCorrelationCookie = "user_id"

// and a request
r, _ := http.NewRequest("GET", "http://www.example.org/foo?q=bar", nil)
r.Header = http.Header{
CorrelationIdHeader: {"correlation-123"},
"Cookie": {"user_id=user-id-xyz; ignore=me; foo=bar;"},
"Cookie": {"ignore=me; foo=bar;"},
}

resp := &http.Response{
Expand All @@ -82,7 +80,6 @@ func Test_Logger_Call(t *testing.T) {

a.Equal("warning", data.Level)
a.Equal("correlation-123", data.CorrelationId)
a.Equal("user-id-xyz", data.UserCorrelationId)
a.InDelta(1000, data.Duration, 0.5)
a.Equal("", data.Error)
a.Equal("www.example.org", data.Host)
Expand All @@ -106,7 +103,6 @@ func Test_Logger_Call(t *testing.T) {
a.Equal("oops", data.Error)
a.Equal("oops", data.Message)
a.Equal("correlation-123", data.CorrelationId)
a.Equal("user-id-xyz", data.UserCorrelationId)
a.InDelta(1000, data.Duration, 0.5)
a.Equal("www.example.org", data.Host)
a.Equal("GET", data.Method)
Expand All @@ -121,15 +117,14 @@ func Test_Logger_Access(t *testing.T) {
b := bytes.NewBuffer(nil)
Logger.Out = b
AccessLogCookiesBlacklist = []string{"ignore", "user_id"}
UserCorrelationCookie = "user_id"

// Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36

// and a request
r, _ := http.NewRequest("GET", "http://www.example.org/foo?q=bar", nil)
r.Header = http.Header{
CorrelationIdHeader: {"correlation-123"},
"Cookie": {"user_id=user-id-xyz; ignore=me; foo=bar;"},
"Cookie": {"ignore=me; foo=bar;"},
"User-Agent": {"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"},
}
r.RemoteAddr = "127.0.0.1"
Expand All @@ -156,7 +151,6 @@ func Test_Logger_Access(t *testing.T) {
a.Equal(201, data.ResponseStatus)
a.Equal("access", data.Type)
a.Equal("/foo?q=bar", data.URL)
a.Equal("user-id-xyz", data.UserCorrelationId)
a.Equal("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36", data.UserAgent)
}

Expand Down Expand Up @@ -198,18 +192,15 @@ func Test_Logger_Application(t *testing.T) {
a := assert.New(t)

// given:
UserCorrelationCookie = "user_id"
header := http.Header{
CorrelationIdHeader: {"correlation-123"},
"Cookie": {"user_id=user-id-xyz;"},
}

// when:
entry := Application(header)

// then:
a.Equal("correlation-123", entry.Data["correlation_id"])
a.Equal("user-id-xyz", entry.Data["user_correlation_id"])
}

func Test_Logger_LifecycleStart(t *testing.T) {
Expand Down

0 comments on commit 64f4b59

Please sign in to comment.