Skip to content

Commit

Permalink
daemon: move hubble specific code to a dedicated file
Browse files Browse the repository at this point in the history
This commit brings no functional changes.

Signed-off-by: Robin Hahling <robin.hahling@gw-computing.net>
  • Loading branch information
rolinh authored and borkmann committed Mar 25, 2020
1 parent 168a047 commit 94dba01
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 59 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ daemon/ @cilium/agent
daemon/cmd/datapath.* @cilium/bpf
daemon/cmd/endpoint.* @cilium/endpoint
daemon/cmd/health.* @cilium/health
daemon/cmd/hubble.go @cilium/hubble
daemon/cmd/ipcache.* @cilium/ipcache
daemon/cmd/k8s_watcher.* @cilium/kubernetes
daemon/cmd/loadbalancer.* @cilium/loadbalancer
Expand Down
59 changes: 0 additions & 59 deletions daemon/cmd/daemon_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/cilium/cilium/api/v1/server"
"github.com/cilium/cilium/api/v1/server/restapi"
"github.com/cilium/cilium/common"
"github.com/cilium/cilium/pkg/api"
"github.com/cilium/cilium/pkg/bpf"
"github.com/cilium/cilium/pkg/cgroups"
"github.com/cilium/cilium/pkg/cleanup"
Expand All @@ -43,9 +42,7 @@ import (
"github.com/cilium/cilium/pkg/defaults"
"github.com/cilium/cilium/pkg/envoy"
"github.com/cilium/cilium/pkg/flowdebug"
"github.com/cilium/cilium/pkg/hubble"
"github.com/cilium/cilium/pkg/identity"
"github.com/cilium/cilium/pkg/ipcache"
"github.com/cilium/cilium/pkg/k8s"
"github.com/cilium/cilium/pkg/k8s/watchers"
"github.com/cilium/cilium/pkg/kvstore"
Expand All @@ -64,11 +61,6 @@ import (
"github.com/cilium/cilium/pkg/probe"
"github.com/cilium/cilium/pkg/sysctl"
"github.com/cilium/cilium/pkg/version"
hubbleServe "github.com/cilium/hubble/cmd/serve"
hubbleMetrics "github.com/cilium/hubble/pkg/metrics"
"github.com/cilium/hubble/pkg/parser"
hubbleServer "github.com/cilium/hubble/pkg/server"
"github.com/cilium/hubble/pkg/server/serveroption"
"github.com/go-openapi/loads"
gops "github.com/google/gops/agent"
"github.com/jessevdk/go-flags"
Expand Down Expand Up @@ -1592,54 +1584,3 @@ func checkNodePortAndEphemeralPortRanges() error {
}
return nil
}

func (d *Daemon) launchHubble() {
logger := logging.DefaultLogger.WithField(logfields.LogSubsys, "hubble")
if !option.Config.EnableHubble {
logger.Info("Hubble server is disabled")
return
}
addresses := append(option.Config.HubbleListenAddresses, "unix://"+option.Config.HubbleSocketPath)
for _, address := range addresses {
// TODO: remove warning once mutual TLS has been implemented
if !strings.HasPrefix(address, "unix://") {
logger.WithField("address", address).Warn("Hubble server will be exposing its API insecurely on this address")
}
}
payloadParser, err := parser.New(d, d, d, ipcache.IPIdentityCache, d)
if err != nil {
logger.WithError(err).Error("Failed to initialize Hubble")
return
}
s, err := hubbleServer.NewLocalServer(payloadParser, logger,
serveroption.WithMaxFlows(option.Config.HubbleFlowBufferSize),
serveroption.WithMonitorBuffer(option.Config.HubbleEventQueueSize))
if err != nil {
logger.WithError(err).Error("Failed to initialize Hubble")
return
}
go s.Start()
d.monitorAgent.GetMonitor().RegisterNewListener(d.ctx, hubble.NewHubbleListener(s))

listeners, err := hubbleServe.SetupListeners(addresses, api.CiliumGroupName)
if err != nil {
logger.WithError(err).Error("Failed to initialize Hubble")
return
}

logger.WithField("addresses", addresses).Info("Starting Hubble server")
if err := hubbleServe.Serve(d.ctx, logger, listeners, s); err != nil {
logger.WithError(err).Error("Failed to start Hubble server")
return
}
if option.Config.HubbleMetricsServer != "" {
logger.WithFields(logrus.Fields{
"address": option.Config.HubbleMetricsServer,
"metrics": option.Config.HubbleMetrics,
}).Info("Starting Hubble Metrics server")
if err := hubbleMetrics.EnableMetrics(log, option.Config.HubbleMetricsServer, option.Config.HubbleMetrics); err != nil {
logger.WithError(err).Warn("Failed to initialize Hubble metrics server")
return
}
}
}
84 changes: 84 additions & 0 deletions daemon/cmd/hubble.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2020 Authors of Cilium
//
// Licensed 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 cmd

import (
"strings"

"github.com/cilium/cilium/pkg/api"
"github.com/cilium/cilium/pkg/hubble"
"github.com/cilium/cilium/pkg/ipcache"
"github.com/cilium/cilium/pkg/logging"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/option"

hubbleServe "github.com/cilium/hubble/cmd/serve"
hubbleMetrics "github.com/cilium/hubble/pkg/metrics"
"github.com/cilium/hubble/pkg/parser"
hubbleServer "github.com/cilium/hubble/pkg/server"
"github.com/cilium/hubble/pkg/server/serveroption"
"github.com/sirupsen/logrus"
)

func (d *Daemon) launchHubble() {
logger := logging.DefaultLogger.WithField(logfields.LogSubsys, "hubble")
if !option.Config.EnableHubble {
logger.Info("Hubble server is disabled")
return
}
addresses := append(option.Config.HubbleListenAddresses, "unix://"+option.Config.HubbleSocketPath)
for _, address := range addresses {
// TODO: remove warning once mutual TLS has been implemented
if !strings.HasPrefix(address, "unix://") {
logger.WithField("address", address).Warn("Hubble server will be exposing its API insecurely on this address")
}
}
payloadParser, err := parser.New(d, d, d, ipcache.IPIdentityCache, d)
if err != nil {
logger.WithError(err).Error("Failed to initialize Hubble")
return
}
s, err := hubbleServer.NewLocalServer(payloadParser, logger,
serveroption.WithMaxFlows(option.Config.HubbleFlowBufferSize),
serveroption.WithMonitorBuffer(option.Config.HubbleEventQueueSize))
if err != nil {
logger.WithError(err).Error("Failed to initialize Hubble")
return
}
go s.Start()
d.monitorAgent.GetMonitor().RegisterNewListener(d.ctx, hubble.NewHubbleListener(s))

listeners, err := hubbleServe.SetupListeners(addresses, api.CiliumGroupName)
if err != nil {
logger.WithError(err).Error("Failed to initialize Hubble")
return
}

logger.WithField("addresses", addresses).Info("Starting Hubble server")
if err := hubbleServe.Serve(d.ctx, logger, listeners, s); err != nil {
logger.WithError(err).Error("Failed to start Hubble server")
return
}
if option.Config.HubbleMetricsServer != "" {
logger.WithFields(logrus.Fields{
"address": option.Config.HubbleMetricsServer,
"metrics": option.Config.HubbleMetrics,
}).Info("Starting Hubble Metrics server")
if err := hubbleMetrics.EnableMetrics(log, option.Config.HubbleMetricsServer, option.Config.HubbleMetrics); err != nil {
logger.WithError(err).Warn("Failed to initialize Hubble metrics server")
return
}
}
}

0 comments on commit 94dba01

Please sign in to comment.