Skip to content

Commit

Permalink
Merge pull request #18 from philips-software/release/v1.0.0
Browse files Browse the repository at this point in the history
Release/v1.0.0
  • Loading branch information
krmeda authored Jul 12, 2019
2 parents 4369baf + 6e357a5 commit 982dae0
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 27 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

/*.env
/*.yml
/logproxy
Expand Down
10 changes: 6 additions & 4 deletions buildscript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ set -x

GIT_COMMIT=$(git rev-parse --short HEAD)

cd $GOPATH
CURRENT_DIR="$(pwd)"
cd "${GOPATH}"
wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.16.0

cd /src
cd src
go mod download
go get -u github.com/jstemmer/go-junit-report
go get -u github.com/t-yuki/gocover-cobertura

rm -rf build/ && mkdir -p build
cd "${CURRENT_DIR}"
go build -ldflags "-X main.commit=${GIT_COMMIT}" -o build/logproxy .
go test -coverprofile build/coverage.out -covermode count -v ./... 2>&1 > build/test-result.txt
go test -coverprofile build/coverage.out -covermode count -v ./... 2>&1 > build/test-result.txt
go-junit-report < build/test-result.txt > build/TEST-report.xml
gocover-cobertura < build/coverage.out > build/coverage-cobertura.xml
golangci-lint run
golangci-lint run
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Jeffail/gabs v1.4.0 h1://5fYRRTq1edjfIrQGvdkcd22pkYUrHZ5YC/H2GJVAo=
github.com/Jeffail/gabs v1.4.0/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
18 changes: 18 additions & 0 deletions handlers/ph_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,33 @@ func (h *PHLogger) processMessage(rfcLogMessage syslog.Message) (*logging.Resour
if dhp.TransactionID != "" {
msg.TransactionID = dhp.TransactionID
}
if dhp.EventID != "" {
msg.EventID = dhp.EventID
}
if dhp.LogData.Message != "" {
msg.LogData.Message = dhp.LogData.Message
}
if dhp.ApplicationVersion != "" {
msg.ApplicationVersion = dhp.ApplicationVersion
}
if dhp.ApplicationName != "" {
msg.ApplicationName = dhp.ApplicationName
}
if dhp.ServiceName != "" {
msg.ServiceName = dhp.ServiceName
}
if dhp.ServerName != "" {
msg.ServerName = dhp.ServerName
}
if dhp.Category != "" {
msg.Category = dhp.Category
}
if dhp.Component != "" {
msg.Component = dhp.Component
}
if dhp.Severity != "" {
msg.Severity = dhp.Severity
}
if h.debug {
h.log.Debugf("DHP --> %s\n", *logMessage)
}
Expand Down
60 changes: 37 additions & 23 deletions handlers/ph_logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ func (n *NilStorer) StoreResources(msgs []logging.Resource, count int) (*logging
}

func TestProcessMessage(t *testing.T) {
var payload = `Starting Application on 50676a99-dce0-418a-6b25-1e3d with PID 8 (/home/vcap/app/BOOT-INF/classes started by vcap in /home/vcap/app)`
var appVersion = `1.0-f53a57a`
var transactionID = `eea9f72c-09b6-4d56-905b-b518fc4dc5b7`

var rawMessage = `<14>1 2018-09-07T15:39:21.132433+00:00 suite-phs.staging.msa-eustaging 7215cbaa-464d-4856-967c-fd839b0ff7b2 [APP/PROC/WEB/0] - - {"app":"msa-eustaging","val":{"message":"` + payload + `"},"ver":"` + appVersion + `","evt":null,"sev":"INFO","cmp":"CPH","trns":"` + transactionID + `","usr":null,"srv":"msa-eustaging.eu-west.philips-healthsuite.com","service":"msa","inst":"50676a99-dce0-418a-6b25-1e3d","cat":"Tracelog","time":"2018-09-07T15:39:21Z"}`

var appName = `7215cbaa-464d-4856-967c-fd839b0ff7b2`
var hostName = `suite-phs.staging.msa-eustaging`
var nonDHPMessage = `<14>1 2018-09-07T15:39:18.517077+00:00 ` + hostName + ` ` + appName + ` [CELL/0] - - Starting health monitoring of container`
const payload = "Starting Application on 50676a99-dce0-418a-6b25-1e3d with PID 8 (/home/vcap/app/BOOT-INF/classes started by vcap in /home/vcap/app)"
const appVersion = "1.0-f53a57a"
const transactionID = "eea9f72c-09b6-4d56-905b-b518fc4dc5b7"

const appName = "7215cbaa-464d-4856-967c-fd839b0ff7b2"
const logAppName = "TestAppName"
const eventTracingId = "b4b0b7d089591aa5:b4b0b7d089591aa5"
const severity = "FATAL"
const component = "TestComponent"
const serviceName = "com.philips.MyLoggingClass"
const serverName = "396f1a94-86f3-470b-784c-17cc"
const category = "TraceLog"
const rawMessage = `<14>1 2018-09-07T15:39:21.132433+00:00 suite-phs.staging.msa-eustaging ` + appName + ` [APP/PROC/WEB/0] - - {"app":"` + logAppName + `","val":{"message":"` + payload + `"},"ver":"` + appVersion + `","evt":"` + eventTracingId + `","sev":"` + severity + `","cmp":"` + component + `","trns":"` + transactionID + `","usr":null,"srv":"` + serverName + `","service":"` + serviceName + `","inst":"50676a99-dce0-418a-6b25-1e3d","cat":"` + category + `","time":"2018-09-07T15:39:21Z"}`

const hostName = `suite-phs.staging.msa-eustaging`
const nonDHPMessage = `<14>1 2018-09-07T15:39:18.517077+00:00 ` + hostName + ` ` + appName + ` [CELL/0] - - Starting health monitoring of container`

parser := rfc5424.NewParser()

Expand All @@ -50,9 +57,16 @@ func TestProcessMessage(t *testing.T) {
resource, err := phLogger.processMessage(msg)
assert.Nilf(t, err, "Expected processMessage() to succeed")
assert.NotNilf(t, resource, "Proccessed resource should not be nil")
assert.Equal(t, resource.ApplicationVersion, appVersion)
assert.Equal(t, resource.TransactionID, transactionID)
assert.Equal(t, resource.LogData.Message, payload)
assert.Equal(t, appVersion, resource.ApplicationVersion)
assert.Equal(t, logAppName, resource.ApplicationName)
assert.Equal(t, category, resource.Category)
assert.Equal(t, component, resource.Component)
assert.Equal(t, transactionID, resource.TransactionID)
assert.Equal(t, eventTracingId, resource.EventID)
assert.Equal(t, serviceName, resource.ServiceName)
assert.Equal(t, serverName, resource.ServerName)
assert.Equal(t, severity, resource.Severity)
assert.Equal(t, payload, resource.LogData.Message)

msg, err = parser.Parse([]byte(nonDHPMessage))

Expand All @@ -62,10 +76,10 @@ func TestProcessMessage(t *testing.T) {

assert.Nilf(t, err, "Expected Parse() to succeed")

assert.Equal(t, resource.LogTime, "2018-09-07T15:39:18.517Z")
assert.Equal(t, resource.ApplicationName, appName)
assert.Equal(t, resource.ServerName, hostName)
assert.Equal(t, resource.LogData.Message, "Starting health monitoring of container")
assert.Equal(t, "2018-09-07T15:39:18.517Z", resource.LogTime)
assert.Equal(t, appName, resource.ApplicationName)
assert.Equal(t, hostName, resource.ServerName)
assert.Equal(t, "Starting health monitoring of container", resource.LogData.Message)
}

type fakeAcknowledger struct {
Expand All @@ -88,10 +102,10 @@ func TestRFC5424Worker(t *testing.T) {
done := make(chan bool)
deliveries := make(chan amqp.Delivery)

var payload = `Starting Application on 50676a99-dce0-418a-6b25-1e3d with PID 8 (/home/vcap/app/BOOT-INF/classes started by vcap in /home/vcap/app)`
var appVersion = `1.0-f53a57a`
var transactionID = `eea9f72c-09b6-4d56-905b-b518fc4dc5b7`
var rawMessage = `<14>1 2018-09-07T15:39:21.132433+00:00 suite-phs.staging.msa-eustaging 7215cbaa-464d-4856-967c-fd839b0ff7b2 [APP/PROC/WEB/0] - - {"app":"msa-eustaging","val":{"message":"` + payload + `"},"ver":"` + appVersion + `","evt":null,"sev":"INFO","cmp":"CPH","trns":"` + transactionID + `","usr":null,"srv":"msa-eustaging.eu-west.philips-healthsuite.com","service":"msa","inst":"50676a99-dce0-418a-6b25-1e3d","cat":"Tracelog","time":"2018-09-07T15:39:21Z"}`
const payload = `Starting Application on 50676a99-dce0-418a-6b25-1e3d with PID 8 (/home/vcap/app/BOOT-INF/classes started by vcap in /home/vcap/app)`
const appVersion = `1.0-f53a57a`
const transactionID = `eea9f72c-09b6-4d56-905b-b518fc4dc5b7`
const rawMessage = `<14>1 2018-09-07T15:39:21.132433+00:00 suite-phs.staging.msa-eustaging 7215cbaa-464d-4856-967c-fd839b0ff7b2 [APP/PROC/WEB/0] - - {"app":"msa-eustaging","val":{"message":"` + payload + `"},"ver":"` + appVersion + `","evt":null,"sev":"INFO","cmp":"CPH","trns":"` + transactionID + `","usr":null,"srv":"msa-eustaging.eu-west.philips-healthsuite.com","service":"msa","inst":"50676a99-dce0-418a-6b25-1e3d","cat":"Tracelog","time":"2018-09-07T15:39:21Z"}`

old := os.Stdout
r, w, _ := os.Pipe()
Expand Down Expand Up @@ -125,7 +139,7 @@ func TestRFC5424Worker(t *testing.T) {
}

func TestWrapResource(t *testing.T) {
var rtrLog = `<14>1 2019-04-12T19:34:43.530045+00:00 suite-xxx.staging.mps 042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9 [RTR/6] - - mps.domain.com - [2019-04-12T19:34:43.528+0000] "GET /test/bogus HTTP/1.1" 200 0 60 "-" "Not A Health Check" "10.10.66.246:48666" "10.10.17.45:61014" x_forwarded_for:"16.19.148.81, 10.10.66.246" x_forwarded_proto:"https" vcap_request_id:"77350158-4a69-47d6-731b-1bc0678db78d" response_time:0.001628089 app_id:"042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9" app_index:"0" x_b3_traceid:"6aa3915b88798203" x_b3_spanid:"6aa3915b88798203" x_b3_parentspanid:"-"`
const rtrLog = `<14>1 2019-04-12T19:34:43.530045+00:00 suite-xxx.staging.mps 042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9 [RTR/6] - - mps.domain.com - [2019-04-12T19:34:43.528+0000] "GET /test/bogus HTTP/1.1" 200 0 60 "-" "Not A Health Check" "10.10.66.246:48666" "10.10.17.45:61014" x_forwarded_for:"16.19.148.81, 10.10.66.246" x_forwarded_proto:"https" vcap_request_id:"77350158-4a69-47d6-731b-1bc0678db78d" response_time:0.001628089 app_id:"042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9" app_index:"0" x_b3_traceid:"6aa3915b88798203" x_b3_spanid:"6aa3915b88798203" x_b3_parentspanid:"-"`

parser := rfc5424.NewParser()

Expand All @@ -139,14 +153,14 @@ func TestWrapResource(t *testing.T) {
resource, err := phLogger.processMessage(msg)

assert.Nilf(t, err, "Expected processMessage() to succeed")
assert.Equal(t, resource.LogTime, "2019-04-12T19:34:43.528Z")
assert.Equal(t, "2019-04-12T19:34:43.528Z", resource.LogTime)
}

func TestDroppedMessages(t *testing.T) {
done := make(chan bool)
deliveries := make(chan amqp.Delivery)

var consulLog = `<14>1 2019-04-12T19:34:43.530045+00:00 suite-xxx.staging.mps 042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9 [RTR/6] - - mps.domain.com - [2019-04-12T19:34:43.528+0000] "GET /test/bogus HTTP/1.1" 200 0 60 "-" "Consul Health Check" "10.10.66.246:48666" "10.10.17.45:61014" x_forwarded_for:"16.19.148.81, 10.10.66.246" x_forwarded_proto:"https" vcap_request_id:"77350158-4a69-47d6-731b-1bc0678db78d" response_time:0.001628089 app_id:"042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9" app_index:"0" x_b3_traceid:"6aa3915b88798203" x_b3_spanid:"6aa3915b88798203" x_b3_parentspanid:"-"`
const consulLog = `<14>1 2019-04-12T19:34:43.530045+00:00 suite-xxx.staging.mps 042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9 [RTR/6] - - mps.domain.com - [2019-04-12T19:34:43.528+0000] "GET /test/bogus HTTP/1.1" 200 0 60 "-" "Consul Health Check" "10.10.66.246:48666" "10.10.17.45:61014" x_forwarded_for:"16.19.148.81, 10.10.66.246" x_forwarded_proto:"https" vcap_request_id:"77350158-4a69-47d6-731b-1bc0678db78d" response_time:0.001628089 app_id:"042cbd0f-1a0e-4f77-ae39-a5c6c9fe2af9" app_index:"0" x_b3_traceid:"6aa3915b88798203" x_b3_spanid:"6aa3915b88798203" x_b3_parentspanid:"-"`

old := os.Stdout
r, w, _ := os.Pipe()
Expand Down

0 comments on commit 982dae0

Please sign in to comment.