You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/08/07 10:54:55 UTC
[GitHub] [dubbo-go-pixiu] maxingg opened a new pull request, #469: WASM Plugin for Pixiu
maxingg opened a new pull request, #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469
<!-- Thanks for sending a pull request!
-->
**What this PR does**:
Pixiu supports the WASM plugin mechanism, and provides a simple implementation of WASM plugins.
**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #432
**Special notes for your reviewer**:
<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
-->
```release-note
Users can choose to load different wasm files which must be stored in the data folder.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950780108
##########
igt/Makefile:
##########
@@ -49,7 +49,7 @@ else
export EXT_NAME ?=
endif
-CGO ?= 0
+CGO ?= 1
Review Comment:
cgo provides a mechanism for golang and C to call each other which is used in wasm-go-sdk, we must active it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] PhilYue merged pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
PhilYue merged PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r957191049
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+ "mosn.io/proxy-wasm-go-host/common"
+ "mosn.io/proxy-wasm-go-host/proxywasm"
+ "mosn.io/proxy-wasm-go-host/wasmer"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+// WasmService manages a collection of WasmInstances of the same type.
+type WasmService struct {
+ rootContextID int32
+ contextIDGenerator int32
+ name string
+ path string
+ mutex sync.Mutex
+ model model.WasmService
+ instancePool sync.Pool
+}
+
+// WasmConfig contains config about every wasmFile.
+type WasmConfig struct {
+ Path string `yaml:"path" json:"path,omitempty"`
+}
+
+// ABIContextWrapper is a request wrapper which indicates request was handled in the wasmInstance.
+type ABIContextWrapper struct {
+ ContextID int32
+ name string
+ Context *proxywasm.ABIContext
+}
+
+func createWasmService(service model.WasmService) (*WasmService, error) {
+ var cfg WasmConfig
+ if err := mapstructure.Decode(service.Config, &cfg); err != nil {
+ return nil, err
+ }
+
+ wasmService := &WasmService{
+ contextIDGenerator: 0,
+ name: service.Name,
+ path: cfg.Path,
+ mutex: sync.Mutex{},
+ model: service,
+ }
+ wasmService.rootContextID = atomic.AddInt32(&wasmService.contextIDGenerator, 1)
+
+ wasmService.instancePool = sync.Pool{
+ New: func() interface{} {
+ pwd, _ := os.Getwd()
+ instance := wasmer.NewWasmerInstanceFromFile(filepath.Join(pwd, cfg.Path))
+ proxywasm.RegisterImports(instance)
Review Comment:
好
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] mark4z commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
mark4z commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950677733
##########
igt/Makefile:
##########
@@ -49,7 +49,7 @@ else
export EXT_NAME ?=
endif
-CGO ?= 0
+CGO ?= 1
Review Comment:
what's this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950780126
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+
Review Comment:
okay
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] mark4z commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
mark4z commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950678111
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+
Review Comment:
agree
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950780314
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+
+ "mosn.io/proxy-wasm-go-host/common"
+
+ "mosn.io/proxy-wasm-go-host/proxywasm"
+
+ "mosn.io/proxy-wasm-go-host/wasmer"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+// WasmService manages a collection of WasmInstances of the same type.
+type WasmService struct {
+ rootContextID int32
+ contextIDGenerator int32
+ name string
+ path string
+ mutex sync.Mutex
+ model model.WasmService
+ instancePool sync.Pool
+}
+
+type WasmConfig struct {
+ Path string `yaml:"path" json:"path,omitempty"`
+}
+
+type ABIContextWrapper struct {
Review Comment:
Do private methods also need to be commented on?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950786955
##########
pkg/filter/http/proxywasm/filter.go:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 proxywasm
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/wasm"
+)
+
+func init() {
+ filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+ Plugin struct {
+ }
+
+ WasmFilterFactory struct {
+ cfg *Config
+ }
+
+ WasmFilter struct {
+ abiContextWrappers map[string]*wasm.ABIContextWrapper
+ }
+
+ Config struct {
+ WasmServices []*Service `yaml:"wasm_services" json:"wasm_services" mapstructure:"wasm_services"`
+ }
+
+ Service struct {
+ Name string `yaml:"name" json:"name" mapstructure:"name"`
+ }
+)
+
+func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus {
+ const HEADER = "header"
+
+ // sample: display http header
+ wrapper := w.abiContextWrappers[HEADER]
+ wrapper.Context.Instance.Lock(wrapper.Context)
+ defer wrapper.Context.Instance.Unlock()
+
+ _ = wrapper.Context.GetExports().ProxyOnContextCreate(wrapper.ContextID, wasm.GetServiceRootID(HEADER))
Review Comment:
okay, I will handle them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] codecov-commenter commented on pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#issuecomment-1221469655
# [Codecov](https://codecov.io/gh/apache/dubbo-go-pixiu/pull/469?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
> Merging [#469](https://codecov.io/gh/apache/dubbo-go-pixiu/pull/469?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2cbc861) into [develop](https://codecov.io/gh/apache/dubbo-go-pixiu/commit/28e040d46a0c754c2390944334d003817fe1e336?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (28e040d) will **decrease** coverage by `0.05%`.
> The diff coverage is `0.00%`.
```diff
@@ Coverage Diff @@
## develop #469 +/- ##
===========================================
- Coverage 37.26% 37.20% -0.06%
===========================================
Files 56 56
Lines 3805 3811 +6
===========================================
Hits 1418 1418
- Misses 2224 2230 +6
Partials 163 163
```
| [Impacted Files](https://codecov.io/gh/apache/dubbo-go-pixiu/pull/469?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
|---|---|---|
| [pkg/common/http/manager.go](https://codecov.io/gh/apache/dubbo-go-pixiu/pull/469/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbW1vbi9odHRwL21hbmFnZXIuZ28=) | `42.85% <0.00%> (-1.74%)` | :arrow_down: |
| [pkg/context/http/context.go](https://codecov.io/gh/apache/dubbo-go-pixiu/pull/469/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-cGtnL2NvbnRleHQvaHR0cC9jb250ZXh0Lmdv) | `0.00% <0.00%> (ø)` | |
:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] PhilYue commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
PhilYue commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r956715743
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+ "mosn.io/proxy-wasm-go-host/common"
+ "mosn.io/proxy-wasm-go-host/proxywasm"
+ "mosn.io/proxy-wasm-go-host/wasmer"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+// WasmService manages a collection of WasmInstances of the same type.
+type WasmService struct {
+ rootContextID int32
+ contextIDGenerator int32
+ name string
+ path string
+ mutex sync.Mutex
+ model model.WasmService
+ instancePool sync.Pool
+}
+
+// WasmConfig contains config about every wasmFile.
+type WasmConfig struct {
+ Path string `yaml:"path" json:"path,omitempty"`
+}
+
+// ABIContextWrapper is a request wrapper which indicates request was handled in the wasmInstance.
+type ABIContextWrapper struct {
+ ContextID int32
+ name string
+ Context *proxywasm.ABIContext
+}
+
+func createWasmService(service model.WasmService) (*WasmService, error) {
+ var cfg WasmConfig
+ if err := mapstructure.Decode(service.Config, &cfg); err != nil {
+ return nil, err
+ }
+
+ wasmService := &WasmService{
+ contextIDGenerator: 0,
+ name: service.Name,
+ path: cfg.Path,
+ mutex: sync.Mutex{},
+ model: service,
+ }
+ wasmService.rootContextID = atomic.AddInt32(&wasmService.contextIDGenerator, 1)
+
+ wasmService.instancePool = sync.Pool{
+ New: func() interface{} {
+ pwd, _ := os.Getwd()
+ instance := wasmer.NewWasmerInstanceFromFile(filepath.Join(pwd, cfg.Path))
+ proxywasm.RegisterImports(instance)
Review Comment:
instance 做非空判断,或者提前判断 path 下 wasm 文件是否存在,给出友好 log
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] mark4z commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
mark4z commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950678303
##########
pkg/filter/http/proxywasm/filter.go:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 proxywasm
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/wasm"
+)
+
+func init() {
+ filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+ Plugin struct {
+ }
+
+ WasmFilterFactory struct {
+ cfg *Config
+ }
+
+ WasmFilter struct {
+ abiContextWrappers map[string]*wasm.ABIContextWrapper
+ }
+
+ Config struct {
+ WasmServices []*Service `yaml:"wasm_services" json:"wasm_services" mapstructure:"wasm_services"`
+ }
+
+ Service struct {
+ Name string `yaml:"name" json:"name" mapstructure:"name"`
+ }
+)
+
+func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus {
+ const HEADER = "header"
+
+ // sample: display http header
+ wrapper := w.abiContextWrappers[HEADER]
+ wrapper.Context.Instance.Lock(wrapper.Context)
+ defer wrapper.Context.Instance.Unlock()
+
+ _ = wrapper.Context.GetExports().ProxyOnContextCreate(wrapper.ContextID, wasm.GetServiceRootID(HEADER))
Review Comment:
maybe error should not ignored
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] cityiron commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
cityiron commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r950663502
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+
Review Comment:
I think not need split here.
##########
pkg/wasm/service.go:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 wasm
+
+import (
+ "math"
+ "os"
+ "path/filepath"
+ "sync"
+ "sync/atomic"
+)
+
+import (
+ "github.com/mitchellh/mapstructure"
+
+ "mosn.io/proxy-wasm-go-host/common"
+
+ "mosn.io/proxy-wasm-go-host/proxywasm"
+
+ "mosn.io/proxy-wasm-go-host/wasmer"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/model"
+)
+
+// WasmService manages a collection of WasmInstances of the same type.
+type WasmService struct {
+ rootContextID int32
+ contextIDGenerator int32
+ name string
+ path string
+ mutex sync.Mutex
+ model model.WasmService
+ instancePool sync.Pool
+}
+
+type WasmConfig struct {
+ Path string `yaml:"path" json:"path,omitempty"`
+}
+
+type ABIContextWrapper struct {
Review Comment:
Some comments for this struct? I found some methods are also not commented on.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r953734583
##########
pkg/filter/http/proxywasm/filter.go:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 proxywasm
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/wasm"
+)
+
+func init() {
+ filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+ Plugin struct {
+ }
+
+ WasmFilterFactory struct {
+ cfg *Config
+ }
+
+ WasmFilter struct {
+ abiContextWrappers map[string]*wasm.ABIContextWrapper
+ }
+
+ Config struct {
+ WasmServices []*Service `yaml:"wasm_services" json:"wasm_services" mapstructure:"wasm_services"`
+ }
+
+ Service struct {
+ Name string `yaml:"name" json:"name" mapstructure:"name"`
+ }
+)
+
+func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus {
+ const HEADER = "header"
+
+ // sample: display http header
+ wrapper := w.abiContextWrappers[HEADER]
+ wrapper.Context.Instance.Lock(wrapper.Context)
+ defer wrapper.Context.Instance.Unlock()
+
+ _ = wrapper.Context.GetExports().ProxyOnContextCreate(wrapper.ContextID, wasm.GetServiceRootID(HEADER))
Review Comment:
yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] mark4z commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
mark4z commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r953558913
##########
pkg/filter/http/proxywasm/filter.go:
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 proxywasm
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/wasm"
+)
+
+func init() {
+ filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+ Plugin struct {
+ }
+
+ WasmFilterFactory struct {
+ cfg *Config
+ }
+
+ WasmFilter struct {
+ abiContextWrappers map[string]*wasm.ABIContextWrapper
+ }
+
+ Config struct {
+ WasmServices []*Service `yaml:"wasm_services" json:"wasm_services" mapstructure:"wasm_services"`
+ }
+
+ Service struct {
+ Name string `yaml:"name" json:"name" mapstructure:"name"`
+ }
+)
+
+func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus {
+ const HEADER = "header"
+
+ // sample: display http header
+ wrapper := w.abiContextWrappers[HEADER]
+ wrapper.Context.Instance.Lock(wrapper.Context)
+ defer wrapper.Context.Instance.Unlock()
+
+ _ = wrapper.Context.GetExports().ProxyOnContextCreate(wrapper.ContextID, wasm.GetServiceRootID(HEADER))
Review Comment:
any update?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] PhilYue commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
PhilYue commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r956711027
##########
pkg/filter/http/proxywasm/filter.go:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 proxywasm
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/wasm"
+)
+
+func init() {
+ filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+ Plugin struct {
+ }
+
+ WasmFilterFactory struct {
+ cfg *Config
+ }
+
+ WasmFilter struct {
+ abiContextWrappers map[string]*wasm.ABIContextWrapper
+ }
+
+ Config struct {
+ WasmServices []*Service `yaml:"wasm_services" json:"wasm_services" mapstructure:"wasm_services"`
+ }
+
+ Service struct {
+ Name string `yaml:"name" json:"name" mapstructure:"name"`
+ }
+)
+
+func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus {
+
+ // sample: display http header
+ if wrapper := w.abiContextWrappers[wasm.HeaderLevel]; wrapper != nil {
+ wrapper.Context.Instance.Lock(wrapper.Context)
+ defer wrapper.Context.Instance.Unlock()
+
+ err := wrapper.Context.GetExports().ProxyOnContextCreate(wrapper.ContextID, wasm.GetServiceRootID(wasm.HeaderLevel))
+ if err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call ProxyOnContextCreate failed: %v", err)
+ return filter.Continue
+ }
+
+ _, err = wrapper.Context.GetExports().ProxyOnRequestHeaders(wrapper.ContextID, int32(len(ctx.Request.Header)), 1)
+ if err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call ProxyOnRequestHeaders failed: %v", err)
+ }
+
+ err = wrapper.Context.GetExports().ProxyOnDelete(wrapper.ContextID)
+ if err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call ProxyOnDelete failed: %v", err)
+ }
+ }
+ return filter.Continue
+}
+
+func (w *WasmFilter) Encode(ctx *http.HttpContext) filter.FilterStatus {
+ for _, wrapper := range w.abiContextWrappers {
+ if err := wasm.ContextDone(wrapper); err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call contextDone failed: %v", err)
+ }
+ }
+
+ if val := ctx.GetHeader("go-wasm-header"); val != "" {
+ if _, err := ctx.Writer.Write([]byte(val)); err != nil {
+ logger.Errorf("write response error: %s", err)
+ }
+ }
+ return filter.Continue
+}
+
+func (factory *WasmFilterFactory) Config() interface{} {
+ return factory.cfg
+}
+
+func (factory *WasmFilterFactory) Apply() error {
+ return nil
+}
+
+func (factory *WasmFilterFactory) PrepareFilterChain(ctx *http.HttpContext, chain filter.FilterChain) error {
+ filter := &WasmFilter{
+ abiContextWrappers: make(map[string]*wasm.ABIContextWrapper),
+ }
+ for _, service := range factory.cfg.WasmServices {
+ if abiContext := wasm.CreateABIContextByName(service.Name, ctx); abiContext != nil {
+ filter.abiContextWrappers[service.Name] = abiContext
Review Comment:
此处 abiContext 的key `service.Name` 是不是必须要与文件`key.go` 的 `HeaderLevel` 匹配
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo-go-pixiu] maxingg commented on a diff in pull request #469: WASM Plugin for Pixiu
Posted by GitBox <gi...@apache.org>.
maxingg commented on code in PR #469:
URL: https://github.com/apache/dubbo-go-pixiu/pull/469#discussion_r956722722
##########
pkg/filter/http/proxywasm/filter.go:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ * http://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 proxywasm
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/common/constant"
+ "github.com/apache/dubbo-go-pixiu/pkg/common/extension/filter"
+ "github.com/apache/dubbo-go-pixiu/pkg/context/http"
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+ "github.com/apache/dubbo-go-pixiu/pkg/wasm"
+)
+
+func init() {
+ filter.RegisterHttpFilter(&Plugin{})
+}
+
+type (
+ Plugin struct {
+ }
+
+ WasmFilterFactory struct {
+ cfg *Config
+ }
+
+ WasmFilter struct {
+ abiContextWrappers map[string]*wasm.ABIContextWrapper
+ }
+
+ Config struct {
+ WasmServices []*Service `yaml:"wasm_services" json:"wasm_services" mapstructure:"wasm_services"`
+ }
+
+ Service struct {
+ Name string `yaml:"name" json:"name" mapstructure:"name"`
+ }
+)
+
+func (w *WasmFilter) Decode(ctx *http.HttpContext) filter.FilterStatus {
+
+ // sample: display http header
+ if wrapper := w.abiContextWrappers[wasm.HeaderLevel]; wrapper != nil {
+ wrapper.Context.Instance.Lock(wrapper.Context)
+ defer wrapper.Context.Instance.Unlock()
+
+ err := wrapper.Context.GetExports().ProxyOnContextCreate(wrapper.ContextID, wasm.GetServiceRootID(wasm.HeaderLevel))
+ if err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call ProxyOnContextCreate failed: %v", err)
+ return filter.Continue
+ }
+
+ _, err = wrapper.Context.GetExports().ProxyOnRequestHeaders(wrapper.ContextID, int32(len(ctx.Request.Header)), 1)
+ if err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call ProxyOnRequestHeaders failed: %v", err)
+ }
+
+ err = wrapper.Context.GetExports().ProxyOnDelete(wrapper.ContextID)
+ if err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call ProxyOnDelete failed: %v", err)
+ }
+ }
+ return filter.Continue
+}
+
+func (w *WasmFilter) Encode(ctx *http.HttpContext) filter.FilterStatus {
+ for _, wrapper := range w.abiContextWrappers {
+ if err := wasm.ContextDone(wrapper); err != nil {
+ logger.Warnf("[dubbo-go-pixiu] wasmFilter call contextDone failed: %v", err)
+ }
+ }
+
+ if val := ctx.GetHeader("go-wasm-header"); val != "" {
+ if _, err := ctx.Writer.Write([]byte(val)); err != nil {
+ logger.Errorf("write response error: %s", err)
+ }
+ }
+ return filter.Continue
+}
+
+func (factory *WasmFilterFactory) Config() interface{} {
+ return factory.cfg
+}
+
+func (factory *WasmFilterFactory) Apply() error {
+ return nil
+}
+
+func (factory *WasmFilterFactory) PrepareFilterChain(ctx *http.HttpContext, chain filter.FilterChain) error {
+ filter := &WasmFilter{
+ abiContextWrappers: make(map[string]*wasm.ABIContextWrapper),
+ }
+ for _, service := range factory.cfg.WasmServices {
+ if abiContext := wasm.CreateABIContextByName(service.Name, ctx); abiContext != nil {
+ filter.abiContextWrappers[service.Name] = abiContext
Review Comment:
是的
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org