forked from openservicemesh/osm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(metrics): Add stats.wasm to proxy config
This change propagates the stats.wasm module to each sidecar proxy's config. stats.wasm is built and embedded in the osm-controller binary and configured inline via LDS. Signed-off-by: Jon Huhn <johuhn@microsoft.com>
- Loading branch information
Showing
5 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ _dist/ | |
creds.json | ||
screenlog.* | ||
demo/bin/ | ||
*.wasm | ||
|
||
## Ignore test coverage files | ||
coverage.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package lds | ||
|
||
import ( | ||
"encoding/base64" | ||
"io/ioutil" | ||
"strings" | ||
|
||
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" | ||
xds_wasm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/wasm/v3" | ||
xds_hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3" | ||
xds_wasm_ext "github.com/envoyproxy/go-control-plane/envoy/extensions/wasm/v3" | ||
|
||
"github.com/golang/protobuf/ptypes" | ||
) | ||
|
||
var statsWASMBytes string | ||
|
||
func init() { | ||
b64 := base64.NewDecoder(base64.StdEncoding, strings.NewReader(statsWASMBytes)) | ||
b, _ := ioutil.ReadAll(b64) | ||
statsWASMBytes = string(b) | ||
} | ||
|
||
func getStatsWASMFilter() (*xds_hcm.HttpFilter, error) { | ||
if len(statsWASMBytes) == 0 { | ||
return nil, nil | ||
} | ||
wasmPlug := &xds_wasm.Wasm{ | ||
Config: &xds_wasm_ext.PluginConfig{ | ||
Name: "stats", | ||
Vm: &xds_wasm_ext.PluginConfig_VmConfig{ | ||
VmConfig: &xds_wasm_ext.VmConfig{ | ||
Runtime: "envoy.wasm.runtime.v8", | ||
Code: &envoy_config_core_v3.AsyncDataSource{ | ||
Specifier: &envoy_config_core_v3.AsyncDataSource_Local{ | ||
Local: &envoy_config_core_v3.DataSource{ | ||
Specifier: &envoy_config_core_v3.DataSource_InlineBytes{ | ||
InlineBytes: []byte(statsWASMBytes), | ||
}, | ||
}, | ||
}, | ||
}, | ||
AllowPrecompiled: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
wasmAny, err := ptypes.MarshalAny(wasmPlug) | ||
if err != nil { | ||
log.Error().Err(err).Msg("Error marshalling WasmService object") | ||
return nil, err | ||
} | ||
|
||
return &xds_hcm.HttpFilter{ | ||
Name: "envoy.filters.http.wasm", | ||
ConfigType: &xds_hcm.HttpFilter_TypedConfig{ | ||
TypedConfig: wasmAny, | ||
}, | ||
}, nil | ||
} |