Skip to content

Commit

Permalink
Merge branch 'wasm_code_analysis' of github.com:rayowang/layotto into…
Browse files Browse the repository at this point in the history
… wasm_code_analysis
  • Loading branch information
rayowang committed May 26, 2022
2 parents e8a8c49 + 31c7228 commit b1faefd
Show file tree
Hide file tree
Showing 218 changed files with 1,474 additions and 2,560 deletions.
29 changes: 22 additions & 7 deletions .github/workflows/layotto-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,34 @@ jobs:
- name: Format Go
run: |
make check.style
resolve-modules:
name: "🌈️ Resolve Go Modules"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- id: set-matrix
run: sh ./etc/script/resolve-modules.sh
golangci-lint:
name: "👀 Go CI Linter"
needs: [style-check]
needs: [style-check,resolve-modules]
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.1
go-version: 1.14.15
- name: Go Lint Test
run: make check.lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
working-directory: ${{ matrix.workdir }}
args: "--out-${NO_FUTURE}format colored-line-number"

go-unit-test:
name: "👀 Go Unit Test"
Expand All @@ -66,7 +81,7 @@ jobs:
- name: Check out code
uses: actions/checkout@v2
- name: Test Coverage
run: make style.coverage
run: make style.coverage
- name: Post Coverage
run: bash <(curl -s https://codecov.io/bash)

Expand Down Expand Up @@ -247,7 +262,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -271,7 +286,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
35 changes: 25 additions & 10 deletions .github/workflows/layotto-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,35 @@ jobs:
- name: Format Go
run: |
make check.style
resolve-modules:
name: "👀 Resolve Go Modules"
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout Sources
uses: actions/checkout@v2
- id: set-matrix
run: sh ./etc/script/resolve-modules.sh
golangci-lint:
name: "👀 Go CI Linter"
needs: [style-check]
needs: [ style-check,resolve-modules ]
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Go
if: ${{ startsWith(github.ref, 'refs/tags/') }}
uses: actions/setup-go@v3
with:
go-version: 1.18.1
- name: Go Lint Test
run: make check.lint
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.14.15
- name: Go Lint Test
uses: golangci/golangci-lint-action@v3
with:
version: v1.46.2
working-directory: ${{ matrix.workdir }}
args: "--out-${NO_FUTURE}format colored-line-number"

go-unit-test:
name: "👀 Go Unit Test"
Expand Down
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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ run :
- pkg/mock
skip-files :
- .pb.go
- rpc/invoker/mosn/transport_protocol/bolt.go


linters :
Expand All @@ -29,6 +30,8 @@ linters :
- gocyclo
- revive
- goimports
# - errcheck
# - forcetypeassert
# - lll

issues :
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ style.quickstart:
# ==============================================================================
.PHONY: license
license:
# For more details: https://github.com/apache/skywalking-eyes#docker-image
docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix
@$(MAKE) checker.license.fix

# ==============================================================================
## integrate.wasm: Run integration test with wasm.
Expand Down
2 changes: 1 addition & 1 deletion cmd/layotto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp

var cmdStart = cli.Command{
Name: "start",
Usage: "start runtime. For example: ./layotto start -c configs/config_in_memory.json",
Usage: "start runtime. For example: ./layotto start -c configs/config_standalone.json",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Expand Down
3 changes: 3 additions & 0 deletions cmd/layotto_multiple_api/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ func main() {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.GetMessage())
if r.GetMessage() != "Hello world" {
panic("Response message is not `Hello world`. I don't know why!")
}
}
6 changes: 3 additions & 3 deletions cmd/layotto_multiple_api/helloworld/grpc_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ import (
grpc_api "mosn.io/layotto/pkg/grpc"
)

const componentType = "helloworld"
const kind = "helloworld"

// This demo will always use this component name.
const componentName = "in-memory"
const componentName = "demo"

func NewHelloWorldAPI(ac *grpc_api.ApplicationContext) grpc.GrpcAPI {
// 1. convert custom components
name2component := make(map[string]component.HelloWorld)
if len(ac.CustomComponent) != 0 {
// we only care about those components of type "helloworld"
name2comp, ok := ac.CustomComponent[componentType]
name2comp, ok := ac.CustomComponent[kind]
if ok && len(name2comp) > 0 {
for name, v := range name2comp {
// convert them using type assertion
Expand Down
41 changes: 40 additions & 1 deletion cmd/layotto_multiple_api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ import (
"strconv"
"time"

"github.com/dapr/components-contrib/secretstores"
"github.com/dapr/components-contrib/secretstores/aws/parameterstore"
"github.com/dapr/components-contrib/secretstores/aws/secretmanager"
"github.com/dapr/components-contrib/secretstores/azure/keyvault"
gcp_secretmanager "github.com/dapr/components-contrib/secretstores/gcp/secretmanager"
"github.com/dapr/components-contrib/secretstores/hashicorp/vault"
sercetstores_kubernetes "github.com/dapr/components-contrib/secretstores/kubernetes"
secretstore_env "github.com/dapr/components-contrib/secretstores/local/env"
secretstore_file "github.com/dapr/components-contrib/secretstores/local/file"

secretstores_loader "mosn.io/layotto/pkg/runtime/secretstores"

"mosn.io/api"
_ "mosn.io/mosn/pkg/filter/stream/grpcmetric"
"mosn.io/mosn/pkg/stagemanager"
Expand Down Expand Up @@ -392,6 +404,33 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp
return sequencer_inmemory.NewInMemorySequencer()
}),
),
// secretstores
runtime.WithSecretStoresFactory(
secretstores_loader.NewFactory("kubernetes", func() secretstores.SecretStore {
return sercetstores_kubernetes.NewKubernetesSecretStore(loggerForDaprComp)
}),
secretstores_loader.NewFactory("azure.keyvault", func() secretstores.SecretStore {
return keyvault.NewAzureKeyvaultSecretStore(loggerForDaprComp)
}),
secretstores_loader.NewFactory("hashicorp.vault", func() secretstores.SecretStore {
return vault.NewHashiCorpVaultSecretStore(loggerForDaprComp)
}),
secretstores_loader.NewFactory("aws.secretmanager", func() secretstores.SecretStore {
return secretmanager.NewSecretManager(loggerForDaprComp)
}),
secretstores_loader.NewFactory("aws.parameterstore", func() secretstores.SecretStore {
return parameterstore.NewParameterStore(loggerForDaprComp)
}),
secretstores_loader.NewFactory("gcp.secretmanager", func() secretstores.SecretStore {
return gcp_secretmanager.NewSecreteManager(loggerForDaprComp)
}),
secretstores_loader.NewFactory("local.file", func() secretstores.SecretStore {
return secretstore_file.NewLocalSecretStore(loggerForDaprComp)
}),
secretstores_loader.NewFactory("local.env", func() secretstores.SecretStore {
return secretstore_env.NewEnvSecretStore(loggerForDaprComp)
}),
),
// Custom components
runtime.WithCustomComponentFactory("helloworld",
custom.NewComponentFactory("in-memory", component.NewInMemoryHelloWorld),
Expand All @@ -403,7 +442,7 @@ func NewRuntimeGrpcServer(data json.RawMessage, opts ...grpc.ServerOption) (mgrp

var cmdStart = cli.Command{
Name: "start",
Usage: "start runtime. For example: ./layotto start -c configs/config_in_memory.json",
Usage: "start runtime. For example: ./layotto start -c configs/config_standalone.json",
Flags: []cli.Flag{
cli.StringFlag{
Name: "config, c",
Expand Down
27 changes: 21 additions & 6 deletions components/configstores/apollo/configstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ var (
livenessIndicator *actuators.HealthIndicator
)

const componentName = "apollo"
const (
defaultGroup = "application"
componentName = "apollo"
)

func init() {
readinessIndicator = actuators.NewHealthIndicator()
Expand All @@ -58,8 +61,8 @@ type ConfigStore struct {
listener *changeListener
kvRepo Repository
tagsRepo Repository
kvConfig *RepoConfig
tagsConfig *RepoConfig
kvConfig *repoConfig
tagsConfig *repoConfig
openAPIClient httpClient
}
type httpClient interface {
Expand All @@ -75,7 +78,7 @@ func (c *httpClientImpl) Do(req *http.Request) (*http.Response, error) {
}

func (c *ConfigStore) GetDefaultGroup() string {
return "application"
return defaultGroup
}

func (c *ConfigStore) GetDefaultLabel() string {
Expand Down Expand Up @@ -167,7 +170,7 @@ func (c *ConfigStore) doInit(config *configstores.StoreConfig) error {
}
// TODO make 'env' configurable
// 2. SetConfig client
kvRepoConfig := &RepoConfig{
kvRepoConfig := &repoConfig{
addr: addr,
appId: appId,
env: c.env,
Expand Down Expand Up @@ -472,6 +475,9 @@ func (c *ConfigStore) setItem(appId string, item *configstores.ConfigurationItem
return err
}
req, err := http.NewRequest("PUT", setUrl, strings.NewReader(string(reqBodyJson)))
if err != nil {
return err
}
// add params
q := req.URL.Query()
q.Add("createIfNotExists", "true")
Expand Down Expand Up @@ -535,6 +541,9 @@ func (c *ConfigStore) commit(env string, appId string, cluster string, namespace
return err
}
req, err := http.NewRequest("POST", commitUrl, strings.NewReader(string(reqBodyJson)))
if err != nil {
return err
}
// add headers
c.addHeaderForOpenAPI(req)
// do request
Expand All @@ -553,6 +562,9 @@ func (c *ConfigStore) deleteItem(env string, appId string, cluster string, group
keyWithLabel := c.concatenateKey(key, label)
deleteUrl := fmt.Sprintf(deleteUrlTpl, c.openAPIAddress, env, appId, cluster, group, keyWithLabel)
req, err := http.NewRequest("DELETE", deleteUrl, nil)
if err != nil {
return err
}
// add params
q := req.URL.Query()
q.Add("key", keyWithLabel)
Expand All @@ -571,7 +583,7 @@ func (c *ConfigStore) deleteItem(env string, appId string, cluster string, group
return err
}

func (c *ConfigStore) initTagsClient(tagCfg *RepoConfig) error {
func (c *ConfigStore) initTagsClient(tagCfg *repoConfig) error {
// 1. create if not exist
err := c.createNamespace(c.env, tagCfg.appId, tagCfg.cluster, c.tagsNamespace)
if err != nil {
Expand Down Expand Up @@ -599,6 +611,9 @@ func (c *ConfigStore) createNamespace(env string, appId string, cluster string,
return err
}
req, err := http.NewRequest("POST", url, strings.NewReader(string(reqBodyJson)))
if err != nil {
return err
}
// add headers
c.addHeaderForOpenAPI(req)
log.DefaultLogger.Debugf("createNamespace url: %v, request body: %s, request: %+v", url, reqBodyJson, req)
Expand Down
Loading

0 comments on commit b1faefd

Please sign in to comment.