Skip to content

Commit

Permalink
Merge ec14ff2 into 5bada7f
Browse files Browse the repository at this point in the history
  • Loading branch information
seeflood authored May 24, 2022
2 parents 5bada7f + ec14ff2 commit fd44251
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ application.pid
# integrate test
integrate_test.sh

# production of make script
goimports

# production of quickstart testing
cmd/layotto/layotto
cmd/layotto/nohup.out
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ linters :
- gocyclo
- revive
- goimports
# - errcheck
# - forcetypeassert
# - lll

issues :
Expand Down
19 changes: 3 additions & 16 deletions components/file/hdfs/hdfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ func (h *hdfs) Put(ctx context.Context, stu *file.PutFileStu) error {
}

_, err = client.Write(stu.FileName, stu.DataStream, size)

if err != nil {
return err
}

return nil
return err
}

func (h *hdfs) Get(ctx context.Context, stu *file.GetFileStu) (io.ReadCloser, error) {
Expand Down Expand Up @@ -258,18 +253,10 @@ func (h *hdfs) selectClient(meta map[string]string) (client types.Storager, err
}

func (h *hdfs) createHdfsClient(meta *HdfsMetaData) (types.Storager, error) {
client, err := store.NewStorager(pairs.WithEndpoint(meta.EndPoint))

if err != nil {
return nil, err
}
return client, nil
return store.NewStorager(pairs.WithEndpoint(meta.EndPoint))
}

// ishdfsMetaValid check if the metadata is valid
func (hm *HdfsMetaData) isHdfsMetaValid() bool {
if hm.EndPoint == "" {
return false
}
return true
return hm.EndPoint != ""
}
30 changes: 17 additions & 13 deletions components/file/hdfs/hdfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ import (
"go.beyondstorage.io/v5/types"
)

// config is the raw json data of component's Metadata configuration
const config = `[
const (
// config is the raw json data of component's Metadata configuration
config = `[
{
"endpoint": "tcp:127.0.0.1:9000"
}
]`
endpoint = "127.0.0.1:9000"
tcpEndpoint = "tcp:127.0.0.1:9000"
)

func TestHdfs_Init(t *testing.T) {
hdfs := NewHdfs()
Expand Down Expand Up @@ -63,7 +67,7 @@ func TestHdfs_selectClient(t *testing.T) {
assert.Equal(t, err, ErrInitFailed)

meta := make(map[string]string)
meta["endpoint"] = "tcp:127.0.0.1:9000"
meta["endpoint"] = tcpEndpoint
_, err = hdfs.selectClient(meta)
assert.NotNil(t, err)

Expand Down Expand Up @@ -112,7 +116,7 @@ func TestHdfs_Put(t *testing.T) {
assert.NotNil(t, err)

// convert from string to int64 success
req.Metadata["endpoint"] = "tcp:127.0.0.1:9000"
req.Metadata["endpoint"] = tcpEndpoint
req.Metadata["fileSize"] = "123"
err = hdfs.Put(context.TODO(), req)
assert.NotNil(t, err)
Expand All @@ -138,11 +142,11 @@ func TestHdfs_Get(t *testing.T) {
assert.Equal(t, ErrMissingEndPoint, err)

// client not exist
req.Metadata["endpoint"] = "127.0.0.1:9000"
req.Metadata["endpoint"] = endpoint
_, err = hdfs.Get(context.TODO(), req)
assert.Equal(t, ErrClientNotExist, err)

req.Metadata["endpoint"] = "tcp:127.0.0.1:9000"
req.Metadata["endpoint"] = tcpEndpoint
_, err = hdfs.Get(context.TODO(), req)
assert.NotNil(t, err)

Expand All @@ -168,11 +172,11 @@ func TestHdfs_Del(t *testing.T) {
assert.Equal(t, ErrMissingEndPoint, err)

// client not exist
req.Metadata["endpoint"] = "127.0.0.1:9000"
req.Metadata["endpoint"] = endpoint
err = hdfs.Del(context.TODO(), req)
assert.Equal(t, ErrClientNotExist, err)

req.Metadata["endpoint"] = "tcp:127.0.0.1:9000"
req.Metadata["endpoint"] = tcpEndpoint
err = hdfs.Del(context.TODO(), req)
assert.NotNil(t, err)
}
Expand All @@ -198,11 +202,11 @@ func TestHdfs_List(t *testing.T) {
assert.Equal(t, ErrMissingEndPoint, err)
assert.Nil(t, resp)

req.Metadata["endpoint"] = "127.0.0.1:9000"
req.Metadata["endpoint"] = endpoint
resp, err = hdfs.List(context.TODO(), req)
assert.Equal(t, ErrClientNotExist, err)

req.Metadata["endpoint"] = "tcp:127.0.0.1:9000"
req.Metadata["endpoint"] = tcpEndpoint
resp, err = hdfs.List(context.TODO(), req)
assert.NotNil(t, err)
}
Expand All @@ -227,11 +231,11 @@ func TestHdfs_Stat(t *testing.T) {
assert.Equal(t, ErrNotSpecifyEndpoint, err)
assert.Nil(t, resp)

req.Metadata["endpoint"] = "127.0.0.1:9000"
req.Metadata["endpoint"] = endpoint
resp, err = hdfs.Stat(context.TODO(), req)
assert.Equal(t, ErrClientNotExist, err)

req.Metadata["endpoint"] = "tcp:127.0.0.1:9000"
req.Metadata["endpoint"] = tcpEndpoint
resp, err = hdfs.Stat(context.TODO(), req)
assert.NotNil(t, err)
}
Expand All @@ -253,7 +257,7 @@ func TestHdfs_CreateHdfsClient(t *testing.T) {
assert.Nil(t, store)
assert.Error(t, err)

mt.EndPoint = "tcp:127.0.0.1:9000"
mt.EndPoint = tcpEndpoint
store, err = oss.(*hdfs).createHdfsClient(mt)
assert.Nil(t, store)
assert.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/start/trace/trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ curl --location --request GET 'http://127.0.0.1:34903/metrics'
解释一下[runtime_config.json](https://github.com/mosn/layotto/blob/main/configs/runtime_config.json) 里 metrics 相关配置

#### 埋点、统计
![](https://user-images.githubusercontent.com/26001097/151318373-632e93bc-108d-47ae-b401-6092ed66bcdc.png)
<img src="https://user-images.githubusercontent.com/26001097/151318373-632e93bc-108d-47ae-b401-6092ed66bcdc.png" width="50%" height="50%" />

图中标红的这段配置会启用mosn的"grpc_metric" filter。这个filter的作用是在每次处理完grpc请求后,统计服务名、成功还是失败等信息,存在内存中。

Expand Down
6 changes: 5 additions & 1 deletion make/golang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ go.test: go.test.verify
.PHONY: go.style
go.style:
@echo "===========> Running go style check"
$(GO) fmt ./... && git status && [[ -z `git status -s` ]]
$(MAKE) format && git status && [[ -z `git status -s` ]]

.PHONY: go.format.verify
go.format.verify:
Expand Down Expand Up @@ -152,3 +152,7 @@ go.format: go.format.verify
$(GO_FMT) -s -w .
$(GOPATH)/bin/$(GO_IMPORTS) -w -local $(GO_MODULE) .
$(GO) mod tidy
cd components && $(GO) mod tidy
cd demo && $(GO) mod tidy
cd sdk/go-sdk && $(GO) mod tidy
cd spec && $(GO) mod tidy
3 changes: 2 additions & 1 deletion pkg/actuator/health/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ func TestEndpoint_WhenNoIndicator(t *testing.T) {
assert.True(t, err != nil)
assert.True(t, len(handle) == 2)
assert.True(t, handle["status"] == DOWN)
health := handle["components"].(map[string]Health)["test"]
health, ok := handle["components"].(map[string]Health)["test"]
assert.True(t, ok)
assert.True(t, health.Status == DOWN)
assert.True(t, health.GetDetail("reason") == "mock")
}
3 changes: 2 additions & 1 deletion pkg/grpc/default_api/api_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func TestGetFile(t *testing.T) {
mockStream.EXPECT().Send(&runtimev1pb.GetFileResponse{Data: []byte("testFile")}).Times(1)
mockStream.EXPECT().Context().Return(context.Background())
go SendData(w)
api.GetFile(&runtimev1pb.GetFileRequest{StoreName: "mock"}, mockStream)
err = api.GetFile(&runtimev1pb.GetFileRequest{StoreName: "mock"}, mockStream)
assert.Nil(t, err)
}

func TestPutFile(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ func TestMosnRuntime_initOutputBinding(t *testing.T) {
m.runtimeConfig.Bindings["mockOutbindings"] = mbindings.Metadata{
Metadata: mdata,
}
m.initOutputBinding(registry)
err := m.initOutputBinding(registry)
assert.Nil(t, err)
assert.NotNil(t, m.outputBindings["mockOutbindings"])
}

Expand Down
2 changes: 1 addition & 1 deletion spec/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module mosn.io/layotto/spec
go 1.14

require (
github.com/golang/protobuf v1.5.0
github.com/golang/protobuf v1.5.0 // indirect
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.26.0-rc.1
)

0 comments on commit fd44251

Please sign in to comment.