Skip to content

Commit

Permalink
Fix telemetry reported
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Poddar committed Nov 2, 2019
1 parent aa755cf commit 9505980
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pilot/pkg/networking/core/v1alpha3/httproute.go
Expand Up @@ -182,7 +182,7 @@ func (configgen *ConfigGeneratorImpl) buildSidecarOutboundHTTPRouteConfig(env *m

if features.EnableFallthroughRoute.Get() && !useSniffing {
// This needs to be the last virtual host, as routes are evaluated in order.
if isAllowAnyOutbound(node) {
if util.IsAllowAnyOutbound(node) {
virtualHosts = append(virtualHosts, &route.VirtualHost{
Name: util.PassthroughRouteName,
Domains: []string{"*"},
Expand Down
14 changes: 7 additions & 7 deletions pilot/pkg/networking/core/v1alpha3/listener.go
Expand Up @@ -1582,7 +1582,7 @@ func (configgen *ConfigGeneratorImpl) onVirtualOutboundListener(env *model.Envir
push *model.PushContext,
ipTablesListener *xdsapi.Listener) *xdsapi.Listener {

hostname := host.Name(util.BlackHoleCluster)
svc := util.FallThroughFilterChainBlackHoleService
mesh := env.Mesh
redirectPort := &model.Port{
Port: int(mesh.ProxyListenPort),
Expand All @@ -1599,8 +1599,8 @@ func (configgen *ConfigGeneratorImpl) onVirtualOutboundListener(env *model.Envir
// contains just the final passthrough/blackhole
fallbackFilter := ipTablesListener.FilterChains[len(ipTablesListener.FilterChains)-1].Filters[0]

if isAllowAnyOutbound(node) {
hostname = util.PassthroughCluster
if util.IsAllowAnyOutbound(node) {
svc = util.FallThroughFilterChainPassthroughService
}

pluginParams := &plugin.InputParams{
Expand All @@ -1611,10 +1611,7 @@ func (configgen *ConfigGeneratorImpl) onVirtualOutboundListener(env *model.Envir
Push: push,
Bind: "",
Port: redirectPort,
Service: &model.Service{
Hostname: hostname,
Ports: model.PortList{redirectPort},
},
Service: svc,
}

mutable := &plugin.MutableObjects{
Expand Down Expand Up @@ -1749,6 +1746,7 @@ type filterChainOpts struct {
match *listener.FilterChainMatch
listenerFilters []*listener.ListenerFilter
networkFilters []*listener.Filter
isFallThrough bool
}

// buildListenerOpts are the options required to build a Listener
Expand Down Expand Up @@ -2058,6 +2056,7 @@ func appendListenerFallthroughRoute(l *xdsapi.Listener, opts *buildListenerOpts,

opts.filterChainOpts = append(opts.filterChainOpts, &filterChainOpts{
networkFilters: []*listener.Filter{tcpFilter},
isFallThrough: true,
})
l.FilterChains = append(l.FilterChains, &listener.FilterChain{FilterChainMatch: wildcardMatch})

Expand Down Expand Up @@ -2306,6 +2305,7 @@ func getPluginFilterChain(opts buildListenerOpts) []plugin.FilterChain {
} else {
filterChain[id].ListenerProtocol = plugin.ListenerProtocolHTTP
}
filterChain[id].IsFallThrough = opts.filterChainOpts[id].isFallThrough
}

return filterChain
Expand Down
6 changes: 1 addition & 5 deletions pilot/pkg/networking/core/v1alpha3/listener_builder.go
Expand Up @@ -578,7 +578,7 @@ func newTCPProxyOutboundListenerFilter(env *model.Environment, node *model.Proxy
StatPrefix: util.BlackHoleCluster,
ClusterSpecifier: &tcp_proxy.TcpProxy_Cluster{Cluster: util.BlackHoleCluster},
}
if isAllowAnyOutbound(node) {
if util.IsAllowAnyOutbound(node) {
// We need a passthrough filter to fill in the filter stack for orig_dst listener
tcpProxy = &tcp_proxy.TcpProxy{
StatPrefix: util.PassthroughCluster,
Expand All @@ -598,7 +598,3 @@ func newTCPProxyOutboundListenerFilter(env *model.Environment, node *model.Proxy
}
return &filter
}

func isAllowAnyOutbound(node *model.Proxy) bool {
return node.SidecarScope.OutboundTrafficPolicy != nil && node.SidecarScope.OutboundTrafficPolicy.Mode == networking.OutboundTrafficPolicy_ALLOW_ANY
}
12 changes: 11 additions & 1 deletion pilot/pkg/networking/plugin/mixer/mixer.go
Expand Up @@ -143,7 +143,17 @@ func (mixerplugin) OnOutboundListener(in *plugin.InputParams, mutable *plugin.Mu
}
} else {
for cnum := range mutable.FilterChains {
mutable.FilterChains[cnum].TCP = append(mutable.FilterChains[cnum].TCP, tcpFilter)
if mutable.FilterChains[cnum].IsFallThrough {
svc := util.FallThroughFilterChainBlackHoleService
if util.IsAllowAnyOutbound(in.Node) {
svc = util.FallThroughFilterChainPassthroughService
}
attrs := createOutboundListenerAttributes(in)
fallThroughFilter := buildOutboundTCPFilter(in.Env.Mesh, attrs, in.Node, svc)
mutable.FilterChains[cnum].TCP = append(mutable.FilterChains[cnum].TCP, fallThroughFilter)
} else {
mutable.FilterChains[cnum].TCP = append(mutable.FilterChains[cnum].TCP, tcpFilter)
}
}
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions pilot/pkg/networking/plugin/plugin.go
Expand Up @@ -141,6 +141,8 @@ type FilterChain struct {
HTTP []*http_conn.HttpFilter
// TCP is the set of network (TCP) filters for this filter chain.
TCP []*listener.Filter
// IsFallthrough indicates if the filter chain is fallthrough.
IsFallThrough bool
}

// MutableObjects is a set of objects passed to On*Listener callbacks. Fields may be nil or empty.
Expand Down
24 changes: 24 additions & 0 deletions pilot/pkg/networking/util/util.go
Expand Up @@ -39,10 +39,12 @@ import (
"github.com/golang/protobuf/ptypes/wrappers"

meshconfig "istio.io/api/mesh/v1alpha1"
networking "istio.io/api/networking/v1alpha3"
"istio.io/pkg/log"

"istio.io/istio/pilot/pkg/features"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pkg/config/host"
)

const (
Expand Down Expand Up @@ -100,6 +102,23 @@ var ALPNInMesh = []string{"istio"}
// ALPNHttp advertises that Proxy is going to talking either http2 or http 1.1.
var ALPNHttp = []string{"h2", "http/1.1"}

// FallThroughFilterChainBlackHoleService is the blackhole service used for fall though
// filter chain
var FallThroughFilterChainBlackHoleService = &model.Service{
Hostname: host.Name(BlackHoleCluster),
Attributes: model.ServiceAttributes{
Name: BlackHoleCluster,
},
}

// FallThroughFilterChainPassthroughService is the passthrough service used for fall though
var FallThroughFilterChainPassthroughService = &model.Service{
Hostname: host.Name(PassthroughCluster),
Attributes: model.ServiceAttributes{
Name: PassthroughCluster,
},
}

func getMaxCidrPrefix(addr string) uint32 {
ip := net.ParseIP(addr)
if ip.To4() == nil {
Expand Down Expand Up @@ -620,3 +639,8 @@ func BuildLbEndpointMetadata(uid string, network string, tlsMode string) *core.M

return metadata
}

// IsAllowAnyOutbound checks if allow_any is enabled for outbound traffic
func IsAllowAnyOutbound(node *model.Proxy) bool {
return node.SidecarScope.OutboundTrafficPolicy != nil && node.SidecarScope.OutboundTrafficPolicy.Mode == networking.OutboundTrafficPolicy_ALLOW_ANY
}

0 comments on commit 9505980

Please sign in to comment.