Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kumactl) add install loki for log aggregation #820

Merged
merged 7 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/kuma-dp/pkg/dataplane/accesslogs/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *sender) Connect() error {
}

func (s *sender) Send(record string) error {
_, err := s.conn.Write(append([]byte(record), byte('\n')))
_, err := s.conn.Write([]byte(record))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakubdyszkiewicz what do you think?

return errors.Wrapf(err, "failed to send a log entry to a TCP logging backend: %s", s.address)
}

Expand Down
31 changes: 31 additions & 0 deletions app/kumactl/cmd/completion/testdata/bash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,36 @@ _kumactl_install_ingress()
noun_aliases=()
}

_kumactl_install_logging()
{
last_command="kumactl_install_logging"

command_aliases=()

commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--namespace=")
two_word_flags+=("--namespace")
local_nonpersistent_flags+=("--namespace=")
flags+=("--config-file=")
two_word_flags+=("--config-file")
flags+=("--log-level=")
two_word_flags+=("--log-level")
flags+=("--mesh=")
two_word_flags+=("--mesh")
two_word_flags+=("-m")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_kumactl_install_metrics()
{
last_command="kumactl_install_metrics"
Expand Down Expand Up @@ -1870,6 +1900,7 @@ _kumactl_install()
commands+=("control-plane")
commands+=("dns")
commands+=("ingress")
commands+=("logging")
commands+=("metrics")
commands+=("tracing")

Expand Down
12 changes: 12 additions & 0 deletions app/kumactl/cmd/completion/testdata/zsh.golden
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ function _kumactl_install {
"control-plane:Install Kuma Control Plane on Kubernetes"
"dns:Install DNS to Kubernetes"
"ingress:Install Ingress on Kubernetes"
"logging:Install Logging backend in Kubernetes cluster (Loki)"
"metrics:Install Metrics backend in Kubernetes cluster (Prometheus + Grafana)"
"tracing:Install Tracing backend in Kubernetes cluster (Jaeger)"
)
Expand All @@ -686,6 +687,9 @@ function _kumactl_install {
ingress)
_kumactl_install_ingress
;;
logging)
_kumactl_install_logging
;;
metrics)
_kumactl_install_metrics
;;
Expand Down Expand Up @@ -743,6 +747,14 @@ function _kumactl_install_ingress {
'(-m --mesh)'{-m,--mesh}'[mesh to use]:'
}

function _kumactl_install_logging {
_arguments \
'--namespace[namespace to install logging to]:' \
'--config-file[path to the configuration file to use]:' \
'--log-level[log level: one of off|info|debug]:' \
'(-m --mesh)'{-m,--mesh}'[mesh to use]:'
}

function _kumactl_install_metrics {
_arguments \
'--kuma-cp-address[the address of Kuma CP]:' \
Expand Down
1 change: 1 addition & 0 deletions app/kumactl/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ func NewInstallCmd(pctx *kumactl_cmd.RootContext) *cobra.Command {
cmd.AddCommand(newInstallTracing())
cmd.AddCommand(newInstallIngressCmd())
cmd.AddCommand(newInstallDNS())
cmd.AddCommand(newInstallLogging())
return cmd
}
54 changes: 54 additions & 0 deletions app/kumactl/cmd/install/install_logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package install

import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/Kong/kuma/app/kumactl/pkg/install/data"
"github.com/Kong/kuma/app/kumactl/pkg/install/k8s"

"github.com/Kong/kuma/app/kumactl/pkg/install/k8s/logging"
)

type loggingTemplateArgs struct {
Namespace string
}

func newInstallLogging() *cobra.Command {
args := struct {
Namespace string
}{
Namespace: "kuma-logging",
}
cmd := &cobra.Command{
Use: "logging",
Short: "Install Logging backend in Kubernetes cluster (Loki)",
Long: `Install Logging backend in Kubernetes cluster (Loki) in a 'kuma-logging' namespace`,
RunE: func(cmd *cobra.Command, _ []string) error {
templateArgs := loggingTemplateArgs{
Namespace: args.Namespace,
}

templateFiles, err := data.ReadFiles(logging.Templates)
if err != nil {
return errors.Wrap(err, "Failed to read template files")
}

renderedFiles, err := renderFiles(templateFiles, templateArgs, simpleTemplateRenderer)
if err != nil {
return errors.Wrap(err, "Failed to render template files")
}

sortedResources := k8s.SortResourcesByKind(renderedFiles)

singleFile := data.JoinYAML(sortedResources)

if _, err := cmd.OutOrStdout().Write(singleFile.Data); err != nil {
return errors.Wrap(err, "Failed to output rendered resources")
}
return nil
},
}
cmd.Flags().StringVar(&args.Namespace, "namespace", args.Namespace, "namespace to install logging to")
return cmd
}
89 changes: 89 additions & 0 deletions app/kumactl/cmd/install/install_logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package install_test

import (
"bytes"
"io/ioutil"
"path/filepath"

kuma_version "github.com/Kong/kuma/pkg/version"

. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"

"github.com/Kong/kuma/app/kumactl/cmd"
"github.com/Kong/kuma/app/kumactl/pkg/install/data"
)

var _ = Describe("kumactl install logging", func() {

var stdout *bytes.Buffer
var stderr *bytes.Buffer

BeforeEach(func() {
stdout = &bytes.Buffer{}
stderr = &bytes.Buffer{}
})

type testCase struct {
extraArgs []string
goldenFile string
}

BeforeEach(func() {
kuma_version.Build = kuma_version.BuildInfo{
Version: "0.0.1",
GitTag: "v0.0.1",
GitCommit: "91ce236824a9d875601679aa80c63783fb0e8725",
BuildDate: "2019-08-07T11:26:06Z",
}
})

DescribeTable("should generate Kubernetes resources",
func(given testCase) {
// given
rootCmd := cmd.DefaultRootCmd()
rootCmd.SetArgs(append([]string{"install", "logging"}, given.extraArgs...))
rootCmd.SetOut(stdout)
rootCmd.SetErr(stderr)

// when
err := rootCmd.Execute()
// then
Expect(err).ToNot(HaveOccurred())
// and
Expect(stderr.Bytes()).To(BeNil())

// when
expected, err := ioutil.ReadFile(filepath.Join("testdata", given.goldenFile))
// then
Expect(err).ToNot(HaveOccurred())
// and
expectedManifests := data.SplitYAML(data.File{Data: expected})

// when
actual := stdout.Bytes()
// then
Expect(actual).To(MatchYAML(expected))
// and
actualManifests := data.SplitYAML(data.File{Data: actual})

// and
Expect(len(actualManifests)).To(Equal(len(expectedManifests)))
// and
for i := range expectedManifests {
Expect(actualManifests[i]).To(MatchYAML(expectedManifests[i]))
}
},
Entry("should generate Kubernetes resources with default settings", testCase{
extraArgs: nil,
goldenFile: "install-logging.defaults.golden.yaml",
}),
Entry("should generate Kubernetes resources with custom settings", testCase{
extraArgs: []string{
"--namespace", "kuma",
},
goldenFile: "install-logging.overrides.golden.yaml",
}),
)
})
Loading