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

[patch] divide gateway for future architecture #579

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
01c785d
[patch] divide gateway for future architecture
Jul 2, 2020
18eaad1
Apply suggestions from code review
Jul 22, 2020
df7e5b6
fix
Jul 28, 2020
01191a9
Helm Chart changes for #579 (#582)
rinx Jul 30, 2020
8b56f29
[patch] divide gateway for future architecture
Jul 2, 2020
f08977d
Apply suggestions from code review
Jul 22, 2020
4575c10
fix
Jul 28, 2020
453c524
Helm Chart changes for #579 (#582)
rinx Jul 30, 2020
3a2906f
Merge branch 'feature/architecture/divide-gateway-and-refactor' of ht…
Jul 30, 2020
e0405ba
fix
Aug 3, 2020
c749d46
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 3, 2020
9f9bfc7
fix
Aug 3, 2020
99d95d3
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 5, 2020
97af921
fix
Aug 6, 2020
cc59d05
fix
Aug 7, 2020
8e55c11
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 11, 2020
5e53921
fix
Aug 11, 2020
87cc40d
fix
Aug 11, 2020
96e0774
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 11, 2020
424c71b
fix
Aug 11, 2020
f028042
fix
Aug 11, 2020
a90497c
fix
Aug 11, 2020
ff0f933
fix
Aug 11, 2020
7855b8e
fix
Aug 12, 2020
210fe5c
fix
Aug 12, 2020
7ca9373
fix
Aug 12, 2020
2c65715
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 20, 2020
900210e
fix
Aug 27, 2020
040a8b2
Merge branch 'feature/architecture/divide-gateway-and-refactor' of ht…
Aug 27, 2020
7a7a6d6
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 27, 2020
7d45385
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Aug 27, 2020
4b1bc53
fix
Aug 27, 2020
91ef0f7
fix
Aug 27, 2020
9a05290
fix
Aug 27, 2020
0c43f78
fix
Aug 27, 2020
6b564d7
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 2, 2020
7a5de43
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 2, 2020
c77d157
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 7, 2020
4305b72
fix
Sep 7, 2020
01ecce1
fix
Sep 8, 2020
77e1314
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 8, 2020
5f76467
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 8, 2020
6c804d3
fix
Sep 11, 2020
ae5837b
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 14, 2020
1f87efb
fix
Sep 15, 2020
b3ae73d
fix
Sep 15, 2020
95d31f3
fix
Sep 15, 2020
359cf40
fix
Sep 15, 2020
f43ea54
fix
Sep 17, 2020
bf5b312
fix pbdoc task (#710)
rinx Sep 17, 2020
7ffa0bd
fix
Sep 24, 2020
a6df1d6
Merge remote-tracking branch 'origin/master' into feature/architectur…
Sep 24, 2020
7d0a2df
fix
Sep 24, 2020
4aa2f24
fix
Sep 28, 2020
43ba151
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Sep 28, 2020
aff908d
fix
Sep 28, 2020
6f96131
fix
Sep 28, 2020
2f39d65
fix
Sep 28, 2020
9fb64c3
fix
Sep 28, 2020
cdf2c0e
fix
Sep 29, 2020
b1ea1b0
fix
Oct 1, 2020
17d6c7b
fix
Oct 1, 2020
431d8d0
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Oct 1, 2020
26fd362
fix
Oct 1, 2020
7632858
fix
Oct 1, 2020
b892d11
fix
Oct 1, 2020
f35d673
fix
Oct 1, 2020
0fbd2f3
fix
Oct 1, 2020
3303668
fix
Oct 1, 2020
f47b951
fix
Oct 1, 2020
6eb8100
fix
Oct 1, 2020
2b34c4c
fix
Oct 1, 2020
44b803b
fix
Oct 1, 2020
952413d
fix
Oct 1, 2020
1bac1ce
fix
Oct 1, 2020
48dfd3a
fix
Oct 1, 2020
198c446
fix
Oct 1, 2020
7aca7c0
fix
Oct 2, 2020
1e95546
fix
Oct 2, 2020
bde47af
fix
Oct 2, 2020
09a5160
fix
Oct 2, 2020
f2fd605
Merge branch 'master' into feature/architecture/divide-gateway-and-re…
Oct 4, 2020
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require (
golang.org/x/net v0.0.0-20200707034311-ab3426394381
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
golang.org/x/sys v0.0.0-20200810151505-1b9f1253b3ed
golang.org/x/tools v0.0.0-20200811032001-fd80f4dbb3ea // indirect
golang.org/x/tools v0.0.0-20200811153730-74512f09e4b0 // indirect
gonum.org/v1/hdf5 v0.0.0-20200504100616-496fefe91614
gonum.org/v1/plot v0.7.1-0.20200803120916-6a037fda5e90
google.golang.org/api v0.30.1-0.20200811142409-9e2b1a1ddef6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,8 @@ golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200806022845-90696ccdc692/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200809012840-6f4f008689da h1:ml5G98G4/tdKT1XNq+ky5iSRdKKux0TANlLAzmXT/hg=
golang.org/x/tools v0.0.0-20200809012840-6f4f008689da/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200811032001-fd80f4dbb3ea h1:9ym67RBRK/wN50W0T3g8g1n8viM1D2ofgWufDlMfWe0=
golang.org/x/tools v0.0.0-20200811032001-fd80f4dbb3ea/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200811153730-74512f09e4b0 h1:UQpfk6CmZq0nGdlZ3/lNwnKmVvi0mgAZCyW6L2aZj/Y=
golang.org/x/tools v0.0.0-20200811153730-74512f09e4b0/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
10 changes: 2 additions & 8 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package config

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"strings"
"unsafe"

"github.com/vdaas/vald/internal/encoding/json"
"github.com/vdaas/vald/internal/io/ioutil"
yaml "gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -100,13 +100,7 @@ func GetActualValue(val string) (res string) {
}
res = os.ExpandEnv(val)
if strings.HasPrefix(res, fileValuePrefix) {
path := strings.TrimPrefix(res, fileValuePrefix)
file, err := os.OpenFile(path, os.O_RDONLY, 0600)
defer file.Close()
if err != nil {
return
}
body, err := ioutil.ReadAll(file)
body, err := ioutil.ReadFile(strings.TrimPrefix(res, fileValuePrefix))
if err != nil {
return
}
Expand Down
5 changes: 3 additions & 2 deletions internal/db/storage/blob/s3/reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ func (r *reader) Open(ctx context.Context) (err error) {
}

func (r *reader) getObjectWithBackoff(ctx context.Context, offset, length int64) (io.Reader, error) {
getFunc := func() (interface{}, error) {
return r.getObject(ctx, offset, length)
getFunc := func() (interface{}, bool, error) {
res, err := r.getObject(ctx, offset, length)
return res, err != nil, err
}

b := backoff.New(r.backoffOpts...)
Expand Down
16 changes: 16 additions & 0 deletions internal/io/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
)

func TestNewReaderWithContext(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
r io.Reader
Expand Down Expand Up @@ -86,6 +87,7 @@ func TestNewReaderWithContext(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
Expand All @@ -107,6 +109,7 @@ func TestNewReaderWithContext(t *testing.T) {
}

func TestNewReadCloserWithContext(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
r io.ReadCloser
Expand Down Expand Up @@ -164,6 +167,7 @@ func TestNewReadCloserWithContext(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
Expand All @@ -185,6 +189,7 @@ func TestNewReadCloserWithContext(t *testing.T) {
}

func Test_ctxReader_Read(t *testing.T) {
t.Parallel()
type args struct {
p []byte
}
Expand Down Expand Up @@ -252,6 +257,7 @@ func Test_ctxReader_Read(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
Expand All @@ -277,6 +283,7 @@ func Test_ctxReader_Read(t *testing.T) {
}

func Test_ctxReader_Close(t *testing.T) {
t.Parallel()
type fields struct {
ctx context.Context
r io.Reader
Expand Down Expand Up @@ -330,6 +337,7 @@ func Test_ctxReader_Close(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc()
Expand All @@ -355,6 +363,7 @@ func Test_ctxReader_Close(t *testing.T) {
}

func TestNewWriterWithContext(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
}
Expand Down Expand Up @@ -413,6 +422,7 @@ func TestNewWriterWithContext(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
Expand All @@ -435,6 +445,7 @@ func TestNewWriterWithContext(t *testing.T) {
}

func TestNewWriteCloserWithContext(t *testing.T) {
t.Parallel()
type args struct {
ctx context.Context
w io.WriteCloser
Expand Down Expand Up @@ -492,6 +503,7 @@ func TestNewWriteCloserWithContext(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
Expand All @@ -513,6 +525,7 @@ func TestNewWriteCloserWithContext(t *testing.T) {
}

func Test_ctxWriter_Write(t *testing.T) {
t.Parallel()
type args struct {
p []byte
}
Expand Down Expand Up @@ -580,6 +593,7 @@ func Test_ctxWriter_Write(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
Expand All @@ -605,6 +619,7 @@ func Test_ctxWriter_Write(t *testing.T) {
}

func Test_ctxWriter_Close(t *testing.T) {
t.Parallel()
type fields struct {
ctx context.Context
w io.Writer
Expand Down Expand Up @@ -658,6 +673,7 @@ func Test_ctxWriter_Close(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc()
Expand Down
52 changes: 52 additions & 0 deletions internal/io/ioutil/ioutil.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt )
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package ioutil provides utility function for I/O
package ioutil

import (
"bytes"
"os"

"github.com/vdaas/vald/internal/safety"
)

func ReadFile(path string) ([]byte, error) {
f, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
if err != nil {
return nil, err
}
defer f.Close()

var n int64 = bytes.MinRead
if fi, err := f.Stat(); err == nil {
if size := fi.Size() + bytes.MinRead; size > n {
n = size
}
}

buf := bytes.NewBuffer(make([]byte, 0, n))

err = safety.RecoverFunc(func() (err error) {
_, err = buf.ReadFrom(f)
return err
})()
if err != nil {
return nil, err
}

return buf.Bytes(), nil
}
103 changes: 103 additions & 0 deletions internal/io/ioutil/ioutil_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// Copyright (C) 2019-2020 Vdaas.org Vald team ( kpango, rinx, kmrmt )
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// Package ioutil provides utility function for I/O
package ioutil

import (
"reflect"
"testing"

"github.com/vdaas/vald/internal/errors"
"go.uber.org/goleak"
)

func TestReadFile(t *testing.T) {
t.Parallel()
type args struct {
path string
}
type want struct {
want []byte
err error
}
type test struct {
name string
args args
want want
checkFunc func(want, []byte, error) error
beforeFunc func(args)
afterFunc func(args)
}
defaultCheckFunc := func(w want, got []byte, err error) error {
if !errors.Is(err, w.err) {
return errors.Errorf("got error = %v, want %v", err, w.err)
}
if !reflect.DeepEqual(got, w.want) {
return errors.Errorf("got = %v, want %v", got, w.want)
}
return nil
}
tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
path: "",
},
want: want{},
checkFunc: defaultCheckFunc,
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
path: "",
},
want: want{},
checkFunc: defaultCheckFunc,
}
}(),
*/
}

for _, test := range tests {
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt)
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}
if test.checkFunc == nil {
test.checkFunc = defaultCheckFunc
}

got, err := ReadFile(test.args.path)
if err := test.checkFunc(test.want, got, err); err != nil {
tt.Errorf("error = %v", err)
}

})
}
}
24 changes: 2 additions & 22 deletions internal/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
package tls

import (
"bytes"
"crypto/tls"
"crypto/x509"
"os"
"reflect"

"github.com/vdaas/vald/internal/errors"
"github.com/vdaas/vald/internal/safety"
"github.com/vdaas/vald/internal/io/ioutil"
)

type Config = tls.Config
Expand Down Expand Up @@ -105,28 +103,10 @@ func NewClientConfig(opts ...Option) (*Config, error) {
// NewX509CertPool returns *x509.CertPool struct or error.
// The CertPool will read the certificate from the path, and append the content to the system certificate pool, and return.
func NewX509CertPool(path string) (pool *x509.CertPool, err error) {
f, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
c, err := ioutil.ReadFile(path)
if err != nil {
return nil, err
}
defer f.Close()

var n int64 = bytes.MinRead
if fi, err := f.Stat(); err == nil {
if size := fi.Size() + bytes.MinRead; size > n {
n = size
}
}

buf := bytes.NewBuffer(make([]byte, 0, n))
err = safety.RecoverFunc(func() (err error) {
_, err = buf.ReadFrom(f)
return err
})()
if err != nil {
return nil, err
}
c := buf.Bytes()
if err == nil && c != nil {
pool, err = x509.SystemCertPool()
if err != nil || pool == nil {
Expand Down
Loading