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

Make common.Time discoverable by mapstriface.Time #3812

Merged
merged 3 commits into from
Mar 27, 2017
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 CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
metricset. The configuration option for the feature was renamed from
`cgroups` to `process.cgroups.enabled`. {pull}3519[3519]
- Change fieldnames couchbase.node.couch.*.actual_disk_size.* to couchbase.node.couch.*.disk_size.* {pull}3545[3545]

*Packetbeat*

*Winlogbeat*
Expand Down Expand Up @@ -60,6 +59,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
- Add error handling to system process metricset for when Linux cgroups are missing from the kernel. {pull}3692[3692]
- Add labels to the Docker healthcheck metricset output. {pull}3707[3707]
- Make system process metricset honor the cpu_ticks config option. {issue}3590[3590]
- Support common.Time in mapstriface.toTime() {pull}3812[3812]

*Packetbeat*

Expand Down
19 changes: 15 additions & 4 deletions metricbeat/schema/mapstriface/mapstriface.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,22 @@ func toTime(key string, data map[string]interface{}) (interface{}, error) {
if !exists {
return common.Time(time.Unix(0, 0)), fmt.Errorf("Key %s not found", key)
}
ts, ok := emptyIface.(time.Time)
if !ok {
return common.Time(time.Unix(0, 0)), fmt.Errorf("Expected date, found %T", emptyIface)

switch emptyIface.(type) {
case time.Time:
ts, ok := emptyIface.(time.Time)
if ok {
return common.Time(ts), nil
}
case common.Time:
ts, ok := emptyIface.(common.Time)
if ok {
return ts, nil
}
}
return common.Time(ts), nil

return common.Time(time.Unix(0, 0)), fmt.Errorf("Expected date, found %T", emptyIface)

}

// Time creates a Conv object for converting Time objects.
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/schema/mapstriface/mapstriface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
func TestConversions(t *testing.T) {
ts := time.Now()

cTs := common.Time{}

input := map[string]interface{}{
"testString": "hello",
"testInt": 42,
Expand All @@ -26,6 +28,7 @@ func TestConversions(t *testing.T) {
},
"testNonNestedObj": "hello from top level",
"testTime": ts,
"commonTime": cTs,

// wrong types
"testErrorInt": "42",
Expand All @@ -44,6 +47,7 @@ func TestConversions(t *testing.T) {
"test_string_from_json_num": StrFromNum("testJsonNumber"),
"test_bool": Bool("testBool"),
"test_time": Time("testTime"),
"common_time": Time("commonTime"),
"test_obj_1": s.Object{
"test": Str("testNonNestedObj"),
},
Expand All @@ -66,6 +70,7 @@ func TestConversions(t *testing.T) {
"test_string_from_json_num": "3910564293633576924",
"test_bool": true,
"test_time": common.Time(ts),
"common_time": cTs,
"test_obj_1": common.MapStr{
"test": "hello from top level",
},
Expand Down