-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathlogger_test.go
More file actions
147 lines (123 loc) · 4.11 KB
/
Copy pathlogger_test.go
File metadata and controls
147 lines (123 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package logging
import (
"context"
"io/ioutil"
"path/filepath"
"testing"
"time"
"github.com/apache/arrow/go/v17/arrow"
"github.com/apache/arrow/go/v17/arrow/array"
"github.com/apache/arrow/go/v17/arrow/memory"
"github.com/apache/arrow/go/v17/parquet/file"
"github.com/apache/arrow/go/v17/parquet/pqarrow"
"github.com/stretchr/testify/require"
"github.com/feast-dev/feast/go/protos/feast/types"
"github.com/stretchr/testify/assert"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/feast-dev/feast/go/protos/feast/serving"
)
type DummySink struct{}
func (s *DummySink) Write(recs []arrow.Record) error {
return nil
}
func (s *DummySink) Flush(featureServiceName string) error {
return nil
}
func TestLoggingChannelTimeout(t *testing.T) {
config := LoggerConfig{
SampleRate: 1.0,
LoggingOptions: LoggingOptions{
ChannelCapacity: 1,
EmitTimeout: DefaultOptions.EmitTimeout,
FlushInterval: DefaultOptions.FlushInterval,
WriteInterval: DefaultOptions.WriteInterval,
},
}
logger, err := NewLogger(&FeatureServiceSchema{}, "testFS", &DummySink{}, config)
// stop log processing to check buffering channel
logger.Stop()
logger.WaitUntilStopped()
assert.Nil(t, err)
assert.Empty(t, logger.buffer.logs)
ts := timestamppb.New(time.Now())
newLog := Log{
FeatureStatuses: []serving.FieldStatus{serving.FieldStatus_PRESENT},
EventTimestamps: []*timestamppb.Timestamp{ts, ts},
}
err = logger.EmitLog(&newLog)
assert.Nil(t, err)
newLog2 := Log{
FeatureStatuses: []serving.FieldStatus{serving.FieldStatus_PRESENT},
EventTimestamps: []*timestamppb.Timestamp{ts, ts},
}
err = logger.EmitLog(&newLog2)
// The channel times out and doesn't hang.
assert.NotNil(t, err)
}
func TestLogAndFlushToFile(t *testing.T) {
sink, err := NewFileLogSink(t.TempDir())
assert.Nil(t, err)
schema := &FeatureServiceSchema{
JoinKeys: []string{"driver_id"},
Features: []string{"view__feature"},
JoinKeysTypes: map[string]types.ValueType_Enum{"driver_id": types.ValueType_INT32},
FeaturesTypes: map[string]types.ValueType_Enum{"view__feature": types.ValueType_DOUBLE},
}
config := LoggerConfig{
SampleRate: 1.0,
LoggingOptions: LoggingOptions{
ChannelCapacity: DefaultOptions.ChannelCapacity,
EmitTimeout: DefaultOptions.EmitTimeout,
FlushInterval: DefaultOptions.FlushInterval,
WriteInterval: 10 * time.Millisecond,
},
}
logger, err := NewLogger(schema, "testFS", sink, config)
assert.Nil(t, err)
assert.Nil(t, logger.Log(
map[string]*types.RepeatedValue{
"driver_id": {
Val: []*types.Value{
{
Val: &types.Value_Int32Val{
Int32Val: 111,
},
},
},
},
},
[]*serving.GetOnlineFeaturesResponse_FeatureVector{
{
Values: []*types.Value{{Val: &types.Value_DoubleVal{DoubleVal: 2.0}}},
Statuses: []serving.FieldStatus{serving.FieldStatus_PRESENT},
EventTimestamps: []*timestamppb.Timestamp{timestamppb.Now()},
},
},
[]string{"view__feature"},
map[string]*types.RepeatedValue{},
"req-id",
))
require.Eventually(t, func() bool {
files, _ := ioutil.ReadDir(sink.path)
return len(files) > 0
}, 60*time.Second, 100*time.Millisecond)
files, _ := ioutil.ReadDir(sink.path)
pf, err := file.OpenParquetFile(filepath.Join(sink.path, files[0].Name()), false)
assert.Nil(t, err)
reader, err := pqarrow.NewFileReader(pf, pqarrow.ArrowReadProperties{}, memory.DefaultAllocator)
assert.Nil(t, err)
tbl, err := reader.ReadTable(context.Background())
assert.Nil(t, err)
tr := array.NewTableReader(tbl, -1)
defer tbl.Release()
fieldNameToIdx := make(map[string]int)
for idx, field := range tbl.Schema().Fields() {
fieldNameToIdx[field.Name] = idx
}
tr.Next()
rec := tr.Record()
assert.Equal(t, "req-id", rec.Column(fieldNameToIdx[LOG_REQUEST_ID_FIELD]).(*array.String).Value(0))
assert.EqualValues(t, 111, rec.Column(fieldNameToIdx["driver_id"]).(*array.Int32).Value(0))
assert.EqualValues(t, 2.0, rec.Column(fieldNameToIdx["view__feature"]).(*array.Float64).Value(0))
assert.EqualValues(t, serving.FieldStatus_PRESENT, rec.Column(fieldNameToIdx["view__feature__status"]).(*array.Int32).Value(0))
}