Skip to content

Commit 1b6f558

Browse files
author
Jono Yan
authored
add observedTimestamp (#11)
1 parent 2ecb582 commit 1b6f558

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

enricher/ecs/ecs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ func (enr *Enricher) EnrichRecord(r map[interface{}]interface{}, t time.Time) ma
9494
}
9595
}
9696
return map[interface{}]interface{}{
97-
"resource": resource,
98-
"body": body,
99-
"timestamp": timestamp,
100-
"observedTimestamp": t.UnixMilli(),
97+
"resource": resource,
98+
"body": body,
99+
"timestamp": timestamp,
100+
mappings.OBSERVED_TIMESTAMP: t.UnixMilli(),
101101
}
102102
}

enricher/ecs/ecs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func TestEnrichRecords(t *testing.T) {
6464
"other_key_2": "other_value_2",
6565
"other_key_3": "other_value_3",
6666
},
67-
"timestamp": "1234567890",
68-
"observedTimestamp": int64(1257894425432),
67+
"timestamp": "1234567890",
68+
mappings.OBSERVED_TIMESTAMP: int64(1257894425432),
6969
},
7070
},
7171
}

enricher/eks/eks.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ func NewEnricher() (*Enricher, error) {
2626

2727
var _ enricher.IEnricher = (*Enricher)(nil)
2828

29-
func (e Enricher) EnrichRecord(r map[interface{}]interface{}, _ time.Time) map[interface{}]interface{} {
29+
func (e Enricher) EnrichRecord(r map[interface{}]interface{}, t time.Time) map[interface{}]interface{} {
3030
// add resource attributes
3131
r["resource"] = map[interface{}]interface{}{
3232
mappings.RESOURCE_CLOUD_ACCOUNT_ID: e.AccountId,
3333
mappings.RESOURCE_ACCOUNT_GROUP: e.CanvaAccountFunction,
3434
}
3535

36+
r[mappings.OBSERVED_TIMESTAMP] = t.UnixMilli()
37+
3638
return r
3739
}

enricher/eks/eks_test.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ func TestValidNewEnricher(t *testing.T) {
1818
Name: "Gets AccountId",
1919
Env: map[string]string{
2020
mappings.ENV_ACCOUNT_ID: "1234567890",
21-
mappings.ENV_ACCOUNT_GROUP: DummyAccountGroup,
21+
mappings.ENV_ACCOUNT_GROUP: DummyAccountFunction,
2222
},
2323
Expected: &Enricher{
2424
AccountId: "1234567890",
25-
CanvaAccountFunction: DummyAccountGroup,
25+
CanvaAccountFunction: DummyAccountFunction,
2626
},
2727
},
2828
{
@@ -61,7 +61,7 @@ func TestInvalidNewEnricher(t *testing.T) {
6161
assert.Error(t, err)
6262
}
6363

64-
func TestEnrichRecordsWithAccountId(t *testing.T) {
64+
func TestEnrichRecords(t *testing.T) {
6565
var cases = []struct {
6666
Name string
6767
Enricher Enricher
@@ -72,21 +72,22 @@ func TestEnrichRecordsWithAccountId(t *testing.T) {
7272
Name: "Adds Account Id",
7373
Enricher: Enricher{
7474
AccountId: "1234567",
75-
CanvaAccountFunction: DummyAccountGroup,
75+
CanvaAccountFunction: DummyAccountFunction,
7676
},
7777
Input: map[interface{}]interface{}{
7878
"log": "hello world",
7979
},
8080
Expected: map[interface{}]interface{}{
81-
"log": "hello world",
81+
mappings.OBSERVED_TIMESTAMP: ExpectedTime,
82+
"log": "hello world",
8283
"resource": map[interface{}]interface{}{
8384
mappings.RESOURCE_CLOUD_ACCOUNT_ID: "1234567",
84-
mappings.RESOURCE_ACCOUNT_GROUP: DummyAccountGroup,
85+
mappings.RESOURCE_ACCOUNT_GROUP: DummyAccountFunction,
8586
},
8687
},
8788
},
8889
{
89-
Name: "Adds Account Group",
90+
Name: "Adds Account Group Function",
9091
Enricher: Enricher{
9192
AccountId: DummyAccountId,
9293
CanvaAccountFunction: "PII",
@@ -95,7 +96,8 @@ func TestEnrichRecordsWithAccountId(t *testing.T) {
9596
"log": "hello world",
9697
},
9798
Expected: map[interface{}]interface{}{
98-
"log": "hello world",
99+
mappings.OBSERVED_TIMESTAMP: ExpectedTime,
100+
"log": "hello world",
99101
"resource": map[interface{}]interface{}{
100102
mappings.RESOURCE_CLOUD_ACCOUNT_ID: DummyAccountId,
101103
mappings.RESOURCE_ACCOUNT_GROUP: "PII",
@@ -113,7 +115,11 @@ func TestEnrichRecordsWithAccountId(t *testing.T) {
113115
}
114116

115117
var (
116-
DummyTime = time.Now()
117-
DummyAccountGroup = "general"
118-
DummyAccountId = "Account_Id"
118+
DummyAccountFunction = "general"
119+
DummyAccountId = "Account_Id"
120+
DummyTime = time.Date(2009, time.November, 10, 23, 7, 5, 432000000, time.UTC)
121+
)
122+
123+
var (
124+
ExpectedTime = int64(1257894425432)
119125
)

enricher/mappings/mappings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package mappings
22

3+
const (
4+
OBSERVED_TIMESTAMP = "observedTimestamp"
5+
)
6+
37
const (
48
RESOURCE_CLOUD_ACCOUNT_ID = "cloud.account.id"
59
RESOURCE_ACCOUNT_GROUP = "canva.account.function"

0 commit comments

Comments
 (0)