Skip to content

Commit 231ce8c

Browse files
author
Jonathan Chauncey
committed
feat(logger): Support logger v2
This PR submits the necessary code changes to support the new v2 logger implementation.
1 parent 5947e2b commit 231ce8c

5 files changed

Lines changed: 29 additions & 10 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ kube-create-database:
5555

5656
kube-create-all: kube-create-database kube-create
5757

58+
kube-update: update-manifests
59+
kubectl delete -f manifests/deis-workflow-rc.tmp.yml
60+
kubectl create -f manifests/deis-workflow-rc.tmp.yml
61+
5862
update-manifests:
5963
sed 's#\(image:\) .*#\1 $(IMAGE)#' manifests/deis-workflow-rc.yml \
6064
> manifests/deis-workflow-rc.tmp.yml

client/cmd/apps.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ func AppLogs(appID string, lines int) error {
172172

173173
// printLogs prints each log line with a color matched to its category.
174174
func printLogs(logs string) error {
175-
for _, log := range strings.Split(strings.Trim(logs, `\n`), `\n`) {
175+
for _, log := range strings.Split(logs, `\\n\\n`) {
176176
category := "unknown"
177-
parts := strings.Split(strings.Split(log, ": ")[0], " ")
177+
parts := strings.Split(strings.Split(log, " -- ")[0], " ")
178178
if len(parts) >= 2 {
179179
category = parts[1]
180180
}

client/controller/models/apps/apps.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,21 @@ func Logs(c *client.Client, appID string, lines int) (string, error) {
9898
body, err := c.BasicRequest("GET", u, nil)
9999

100100
if err != nil {
101-
return "", err
101+
return fmt.Sprintf("Error:%v", err), err
102102
}
103103

104-
return strings.Trim(body, `"`), nil
104+
if len(body) < 1 {
105+
return fmt.Sprintf(
106+
`There are currently no log messages. Please check the following things:
107+
1) Logger and fluentd pods are running.
108+
2) The application is writing logs to the logger component.
109+
You can verify that logs are appearing in the logger component by issuing the following command:
110+
curl http://<log service ip>:8088/%s on a kubernetes host.
111+
To get the service ip you can do the following: kubectl get svc deis-logger --namespace=deis`, appID), nil
112+
}
113+
114+
// We need to trim a few characters off the front and end of the string
115+
return body[3 : len(body)-2], nil
105116
}
106117

107118
// Run one time command in an app.

client/controller/models/apps/apps_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ func (f *fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
9696
return
9797
}
9898

99+
// The entire log message is prefixed and suffixed with a few characters (not entirely sure why)
100+
// We mimic those here
99101
if req.URL.Path == "/v2/apps/example-go/logs" && req.URL.RawQuery == "" && req.Method == "GET" {
100-
res.Write([]byte("test\nfoo\nbar\n"))
102+
res.Write([]byte("b'\"test foo bar\"'"))
101103
return
102104
}
103105

106+
// The entire log message is prefixed and suffixed with a few characters (not entirely sure why)
107+
// We mimic those here
104108
if req.URL.Path == "/v2/apps/example-go/logs" && req.URL.RawQuery == "log_lines=1" && req.Method == "GET" {
105-
res.Write([]byte("test\n"))
109+
res.Write([]byte("b'\"test\"'"))
106110
return
107111
}
108112

@@ -333,11 +337,11 @@ func TestAppsLogs(t *testing.T) {
333337
tests := []testExpected{
334338
{
335339
Input: -1,
336-
Expected: "test\nfoo\nbar\n",
340+
Expected: "test foo bar",
337341
},
338342
{
339343
Input: 1,
340-
Expected: "test\n",
344+
Expected: "test",
341345
},
342346
}
343347

rootfs/deis/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
ETCD_PORT = os.environ.get('DEIS_ETCD_1_SERVICE_PORT_CLIENT', 4001)
268268

269269
# default deis settings
270-
LOG_LINES = 1000
270+
LOG_LINES = 100
271271
TEMPDIR = tempfile.mkdtemp(prefix='deis')
272272

273273
# names which apps cannot reserve for routing
@@ -297,7 +297,7 @@
297297
S3EP = '{}:{}'.format(S3EP_HOST, S3EP_PORT)
298298
# logger settings
299299
LOGGER_HOST = os.environ.get('DEIS_LOGGER_SERVICE_HOST', '127.0.0.1')
300-
LOGGER_PORT = os.environ.get('DEIS_LOGGER_SERVICE_PORT', 8088)
300+
LOGGER_PORT = os.environ.get('DEIS_LOGGER_PORT_8088_TCP_PORT', 8088)
301301

302302
# check if we can register users with `deis register`
303303
REGISTRATION_ENABLED = True

0 commit comments

Comments
 (0)