Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ronnie/thread name pathname #24

Merged
merged 5 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN yarn
RUN npm run build

FROM ubuntu:16.04
RUN apt update && apt install libsystemd-dev
RUN apt update && apt install -y libsystemd-dev
COPY --from=server /logserver /usr/bin/logserver
COPY --from=client /client/dist /client/dist
ENTRYPOINT ["logserver"]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: test run-example run-example-dynamic client

test:
go test -race ./... -timeout 30s
go test -race ./... -timeout 30s

run-example:
go run ./main.go -debug -config ./example/logserver.json
Expand Down
10 changes: 9 additions & 1 deletion client/app/components/file-view/file-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FileView extends Component {
activeFs: [],
showTimestamp: true,
showLinenumbers: true,
showThreadName: false,
}

componentWillMount() {
Expand Down Expand Up @@ -134,6 +135,7 @@ class FileView extends Component {
showLevels={levels}
showLinenumbers={this.state.showLinenumbers}
showTimestamp={this.state.showTimestamp}
showThreadName={this.state.showThreadName}
/>
} else {
contentComponent = <div>File is empty</div>
Expand Down Expand Up @@ -172,6 +174,12 @@ class FileView extends Component {
})
}}>Timestamps</Checkbox>

<Checkbox checked={this.state.showThreadName} onChange={({target: {checked}}) => {
this.setState({
showThreadName: checked,
})
}}>Thread Name</Checkbox>


</div>
{contentComponent}
Expand All @@ -180,4 +188,4 @@ class FileView extends Component {
}
}

export default FileView
export default FileView
17 changes: 15 additions & 2 deletions client/app/components/file-view/lines-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LinesView extends Component {
}

static propTypes = {
showThreadName: PropTypes.bool,
showFilename: PropTypes.bool,
showTimestamp: PropTypes.bool,
showLinenumbers: PropTypes.bool,
Expand All @@ -51,6 +52,7 @@ class LinesView extends Component {
}

static defaultProps = {
showThreadName: false,
showFilename: false,
showTimestamp: false,
showLinenumbers: false,
Expand All @@ -74,7 +76,7 @@ class LinesView extends Component {

_getColumns = () => {
const {maxLengths} = this.state
const {showFilename, showTimestamp, showLinenumbers} = this.props
const {showThreadName, showFilename, showTimestamp, showLinenumbers} = this.props

if (showFilename) {
return [
Expand All @@ -95,6 +97,12 @@ class LinesView extends Component {
},
]

if (showThreadName) {
columns.unshift({
width: 100,
name: 'thread',
})
}
if (showTimestamp) {
columns.unshift({
width: 135,
Expand Down Expand Up @@ -191,6 +199,11 @@ class LinesView extends Component {
<Tag key={line.get('level')} color={colorByLevel(line.get('level'))}>{line.get('level')}</Tag> : null
break
}
case 'thread': {
content = line.get('thread') ?
<Tag key={line.get('thread')} >{line.get('thread')}</Tag> : null
break
}
case 'timestamp': {
if (line.get('time')) {
const timestamp = moment(line.get('time'))
Expand Down Expand Up @@ -247,4 +260,4 @@ class LinesView extends Component {
}
}

export {LinesView}
export {LinesView}
9 changes: 7 additions & 2 deletions client/app/components/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const levelsSelector = createSelector(
export const contentSelector = createSelector(
appStateSelector,
levelsSelector,
(app = Map(), levels = Set()) => app.get('content', List()).filter(line => !line.get('level') || levels.includes(line.get('level', '').toLowerCase()))
(app = Map(), levels = Set()) => app.get('content', List()).filter(line => !line.get('level') || levels.includes(line.get('level', '').toLowerCase())).map(line => {
if (line.get('path')) {
return line.set('msg', `${line.get('msg')} (${line.get('path')}:${line.get('lineno')})`)
}
return line
})
)

const findMatches = (content = List(), query) => {
Expand Down Expand Up @@ -110,4 +115,4 @@ export const searchResultsSelector = createSelector(
(app = Map()) => app.get('search_results')
)

export const locationSelect = (state = Map()) => state.get('router').location || {}
export const locationSelect = (state = Map()) => state.get('router').location || {}
5 changes: 4 additions & 1 deletion example/logserver.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
"msg": "msg",
"level": "levelname",
"time": "created",
"args": "args"
"args": "args",
"thread": "threadName",
"path": "pathname",
"lineno": "lineno"
},
"time_formats": [
"unix_float"
Expand Down
18 changes: 18 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ func TestHandler(t *testing.T) {
FileName: "mancala.stratolog",
Line: 1,
Offset: 0,
Thread: "DistributorThread",
LineNo: 162,
Path: "/usr/share/stratostorage/mancala_management_service.egg/mancala/management/distributor/distributor.py",
},
{
Msg: "data disk <disk: hostname=stratonode2.node.strato, ID=2d03c436-c197-464f-9ad0-d861e650cd61, path=/dev/sdc, type=mancala> was found in distributionID:0 table version:1, setting inTable=True",
Expand All @@ -71,6 +74,9 @@ func TestHandler(t *testing.T) {
FileName: "mancala.stratolog",
Line: 2,
Offset: 699,
Thread: "DistributorThread",
LineNo: 162,
Path: "/usr/share/stratostorage/mancala_management_service.egg/mancala/management/distributor/distributor.py",
},
{
Msg: "data disk <disk: hostname=stratonode0.node.strato, ID=f3d510c7-1185-4942-b349-0de055165f78, path=/dev/sdc, type=mancala> was found in distributionID:0 table version:1, setting inTable=True",
Expand All @@ -80,6 +86,9 @@ func TestHandler(t *testing.T) {
FileName: "mancala.stratolog",
Line: 3,
Offset: 1398,
Thread: "DistributorThread",
LineNo: 162,
Path: "/usr/share/stratostorage/mancala_management_service.egg/mancala/management/distributor/distributor.py",
},
},
},
Expand Down Expand Up @@ -141,6 +150,9 @@ func TestHandler(t *testing.T) {
FileName: "mancala.stratolog",
Line: 2,
Offset: 699,
Thread: "DistributorThread",
LineNo: 162,
Path: "/usr/share/stratostorage/mancala_management_service.egg/mancala/management/distributor/distributor.py",
},
},
},
Expand Down Expand Up @@ -186,6 +198,9 @@ func TestHandler(t *testing.T) {
FileName: "mancala.stratolog",
Line: 2,
Offset: 699,
Thread: "DistributorThread",
LineNo: 162,
Path: "/usr/share/stratostorage/mancala_management_service.egg/mancala/management/distributor/distributor.py",
},
},
},
Expand All @@ -209,6 +224,9 @@ func TestHandler(t *testing.T) {
FileName: "mancala.stratolog",
Line: 2,
Offset: 699,
Thread: "DistributorThread",
LineNo: 162,
Path: "/usr/share/stratostorage/mancala_management_service.egg/mancala/management/distributor/distributor.py",
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions parse/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type Log struct {
FileName string `json:"file_name"`
Line int `json:"line"`
Offset int `json:"offset"`
Thread string `json:"thread,omitempty"`
Path string `json:"path,omitempty"`
LineNo int `json:"lineno"`
}

func (l *Log) parseTime(timeFormats []string, timeString string) {
Expand Down
34 changes: 30 additions & 4 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ import (
type Type string

const (
KeyTime = "time"
KeyLevel = "level"
KeyMsg = "msg"
KeyArgs = "args"
KeyTime = "time"
KeyLevel = "level"
KeyMsg = "msg"
KeyArgs = "args"
KeyThreadName = "thread"
KeyPathName = "path"
KeyLineNo = "lineno"
)

// noParserAfter determines how many line should be parsed before choosing a no-parser
Expand Down Expand Up @@ -163,6 +166,29 @@ func (p *parser) parseJson(line []byte) *Log {
log.Msg += argsToMessage(j)
}

if jsonKey, ok := p.JsonMapping[KeyThreadName]; ok {
if log.Thread, ok = j[jsonKey].(string); !ok {
return nil
}
delete(j, jsonKey)
}

if jsonKey, ok := p.JsonMapping[KeyPathName]; ok {
if log.Path, ok = j[jsonKey].(string); !ok {
return nil
}
delete(j, jsonKey)
}

if jsonKey, ok := p.JsonMapping[KeyLineNo]; ok {
var floatLineNo float64
if floatLineNo, ok = j[jsonKey].(float64); !ok {
return nil
}
log.LineNo = int(floatLineNo)
delete(j, jsonKey)
}

return log
}

Expand Down
26 changes: 26 additions & 0 deletions parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ func TestParser(t *testing.T) {
require.Nil(t, err)

parsers, err := New([]Config{
{
Glob: "*.stratolog",
JsonMapping: map[string]string{
"msg": "msg",
"level": "levelname",
"time": "created",
"args": "args",
"thread": "threadName",
"path": "pathname",
"lineno": "lineno",
},
TimeFormats: []string{"unix_float"},
},
{
Glob: "*.jsonlog",
JsonMapping: map[string]string{
Expand Down Expand Up @@ -51,6 +64,19 @@ func TestParser(t *testing.T) {
line string
want *Log
}{
{
name: "stratolog/basic",
logName: "file.stratolog",
line: `{"process": 36154, "args": ["val1", 0, true], "module": "distributor", "funcName": "_updateDisksInTableStates", "exc_text": null, "name": "my-name", "thread": 140189066323712, "created": 1514211785.448693, "threadName": "DistributorThread", "filename": "distributor.py", "levelno": 20, "processName": "MainProcess", "pathname": "/var/lib/file.py", "lineno": 162, "msg": "hello %s you got:%s yes? %s, sure", "levelname": "INFO"}`,
want: &Log{
Msg: `hello val1 you got:0 yes? true, sure`,
Time: &time1,
Level: "INFO",
Thread: "DistributorThread",
Path: "/var/lib/file.py",
LineNo: 162,
},
},
{
name: "jsonlog/list args",
logName: "file.jsonlog",
Expand Down