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

Collector for RRD data #290

Merged
merged 1 commit into from
Nov 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 30 additions & 10 deletions .github/workflows/build-test-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
jobs:
build:
runs-on: ubuntu-18.04
container:
image: replicated/troubleshoot-builder:18.04
credentials:
username: repldeploy2
password: ${{ secrets.DOCKERHUB_PASSWORD }}
steps:
- uses: actions/setup-go@v1
with:
Expand All @@ -24,10 +29,15 @@ jobs:

- uses: actions/checkout@v2

- run: make
- run: make

compile-preflight:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: replicated/troubleshoot-builder:18.04
credentials:
username: repldeploy2
password: ${{ secrets.DOCKERHUB_PASSWORD }}
needs: build
steps:
- uses: actions/setup-go@v1
Expand All @@ -46,20 +56,25 @@ jobs:
path: bin/preflight

validate-preflight:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
needs: compile-preflight
steps:
- name: Download preflight binary
uses: actions/download-artifact@v1
with:
name: preflight
path: bin/
- uses: engineerd/setup-kind@v0.2.0
- uses: engineerd/setup-kind@v0.4.0
- run: chmod +x bin/preflight
- run: ./bin/preflight --interactive=false --format=json https://preflight.replicated.com

compile-supportbundle:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: replicated/troubleshoot-builder:18.04
credentials:
username: repldeploy2
password: ${{ secrets.DOCKERHUB_PASSWORD }}
needs: build
steps:
- uses: actions/setup-go@v1
Expand All @@ -78,23 +93,28 @@ jobs:
path: bin/support-bundle

validate-supportbundle:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
needs: compile-supportbundle
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@master
- name: Download support-bundle binary
uses: actions/download-artifact@v1
with:
name: support-bundle
path: bin/
- uses: engineerd/setup-kind@v0.2.0
- uses: engineerd/setup-kind@v0.4.0
- run: chmod +x bin/support-bundle
- run: ./bin/support-bundle ./examples/support-bundle/sample-collectors.yaml
- run: ./bin/support-bundle ./examples/support-bundle/sample-supportbundle.yaml
- run: ./bin/support-bundle https://kots.io

goreleaser:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: replicated/troubleshoot-builder:18.04
credentials:
username: repldeploy2
password: ${{ secrets.DOCKERHUB_PASSWORD }}
needs:
- validate-preflight
if: startsWith(github.ref, 'refs/tags/v')
Expand All @@ -109,7 +129,7 @@ jobs:

- name: Unshallow
run: git fetch --prune --unshallow

- uses: actions/setup-go@v1
with:
go-version: "1.14"
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ endif

define LDFLAGS
-ldflags "\
-s -w \
-extldflags \"-static\" \
-X ${VERSION_PACKAGE}.version=${VERSION} \
-X ${VERSION_PACKAGE}.gitSHA=${GIT_SHA} \
-X ${VERSION_PACKAGE}.buildTime=${DATE} \
Expand All @@ -47,15 +49,15 @@ test: generate fmt vet

.PHONY: support-bundle
support-bundle: generate fmt vet
go build ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot
go build -tags netgo ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot

.PHONY: preflight
preflight: generate fmt vet
go build ${LDFLAGS} -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight
go build -tags netgo ${LDFLAGS} -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight

.PHONY: analyze
analyze: generate fmt vet
go build ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze
go build -tags netgo ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze

.PHONY: fmt
fmt:
Expand Down Expand Up @@ -118,7 +120,7 @@ snapshot-release:

.PHONY: local-release
local-release:
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.local.yml
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.yaml
docker tag replicated/troubleshoot:alpha localhost:32000/troubleshoot:alpha
docker tag replicated/preflight:alpha localhost:32000/preflight:alpha
docker push localhost:32000/troubleshoot:alpha
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,19 @@ For details on creating the custom resource files that drive support-bundle coll

For questions about using Troubleshoot, there's a [Replicated Community](https://help.replicated.com/community) forum, and a [#app-troubleshoot channel in Kubernetes Slack](https://kubernetes.slack.com/channels/app-troubleshoot).

# Building

The following packages are required for building the project from source code:

pkg-config
librrd-dev
libglib2.0-dev
libcairo2-dev
libpango1.0-dev
libpixman-1-dev
libpng-dev
libsdl-pango-dev
libthai-dev
libpcre3-dev

There are known issues with libc6 2.27-3ubuntu1.2 on Ubuntu 18. Upgrading to 2.27-3ubuntu1.3 (apt-get install libc6) resolves these.
70 changes: 63 additions & 7 deletions cmd/troubleshoot/cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"archive/tar"
"bytes"
"compress/gzip"
"context"
"crypto/tls"
"encoding/json"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/fatih/color"
"github.com/manifoldco/promptui"
"github.com/mattn/go-isatty"
"github.com/mholt/archiver"
"github.com/pkg/errors"
"github.com/replicatedhq/troubleshoot/cmd/util"
analyzer "github.com/replicatedhq/troubleshoot/pkg/analyze"
Expand Down Expand Up @@ -669,14 +669,70 @@ func callbackSupportBundleAPI(r *troubleshootv1beta2.ResultRequest, archivePath
}

func tarSupportBundleDir(inputDir, outputFilename string) error {
tarGz := archiver.TarGz{
Tar: &archiver.Tar{
ImplicitTopLevelFolder: false,
},
fileWriter, err := os.Create(outputFilename)
if err != nil {
return errors.Wrap(err, "failed to create output file")
}
defer fileWriter.Close()

gzipWriter := gzip.NewWriter(fileWriter)
defer gzipWriter.Close()

tarWriter := tar.NewWriter(gzipWriter)
defer tarWriter.Close()

err = filepath.Walk(inputDir, func(filename string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if err := tarGz.Archive([]string{inputDir}, outputFilename); err != nil {
return errors.Wrap(err, "create archive")
fileMode := info.Mode()
if !fileMode.IsRegular() { // support bundle can have only files
return nil
}

nameInArchive, err := filepath.Rel(inputDir, filename)
if err != nil {
return errors.Wrap(err, "failed to create relative file name")
}

// tar.FileInfoHeader call causes a crash in static builds
// https://github.com/golang/go/issues/24787
hdr := &tar.Header{
Name: nameInArchive,
ModTime: info.ModTime(),
Mode: int64(fileMode.Perm()),
Typeflag: tar.TypeReg,
Size: info.Size(),
}

err = tarWriter.WriteHeader(hdr)
if err != nil {
return errors.Wrap(err, "failed to write tar header")
}

err = func() error {
fileReader, err := os.Open(filename)
if err != nil {
return errors.Wrap(err, "failed to open source file")
}
defer fileReader.Close()

_, err = io.Copy(tarWriter, fileReader)
if err != nil {
return errors.Wrap(err, "failed to copy file into archive")
}

return nil
}()
if err != nil {
return err
}

return nil
})
if err != nil {
return errors.Wrap(err, "failed to walk source dir")
}

return nil
Expand Down
34 changes: 32 additions & 2 deletions deploy/.goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ builds:
- id: preflight
goos:
- linux
- darwin
- windows
goarch:
- amd64
env:
- CGO_ENABLED=1
main: cmd/preflight/main.go
ldflags: -s -w
-X github.com/replicatedhq/troubleshoot/pkg/version.version={{.Version}}
-X github.com/replicatedhq/troubleshoot/pkg/version.gitSHA={{.Commit}}
-X github.com/replicatedhq/troubleshoot/pkg/version.buildTime={{.Date}}
-extldflags "-static"
flags: -tags netgo -installsuffix netgo
binary: preflight
hooks: {}
- id: preflight-darwin
goos:
- darwin
goarch:
- amd64
env:
- CGO_ENABLED=0
main: cmd/preflight/main.go
Expand All @@ -37,10 +52,25 @@ builds:
- id: support-bundle
goos:
- linux
- darwin
- windows
goarch:
- amd64
env:
- CGO_ENABLED=1
main: cmd/troubleshoot/main.go
ldflags: -s -w
-X github.com/replicatedhq/troubleshoot/pkg/version.version={{.Version}}
-X github.com/replicatedhq/troubleshoot/pkg/version.gitSHA={{.Commit}}
-X github.com/replicatedhq/troubleshoot/pkg/version.buildTime={{.Date}}
-extldflags "-static"
flags: -tags netgo -installsuffix netgo
binary: support-bundle
hooks: {}
- id: support-bundle-darwin
goos:
- darwin
goarch:
- amd64
env:
- CGO_ENABLED=0
main: cmd/troubleshoot/main.go
Expand Down
10 changes: 3 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/chzyer/logex v1.1.11-0.20160617073814-96a4d311aa9b // indirect
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
github.com/fatih/color v1.7.0
github.com/frankban/quicktest v1.7.2 // indirect
github.com/go-openapi/spec v0.19.4 // indirect
github.com/go-redis/redis/v7 v7.2.0
github.com/go-sql-driver/mysql v1.5.0
github.com/gobwas/glob v0.2.3
github.com/golang/snappy v0.0.1 // indirect
github.com/google/go-cmp v0.3.1 // indirect
github.com/google/gofuzz v1.1.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/hashicorp/go-getter v1.3.1-0.20190627223108-da0323b9545e
Expand All @@ -27,21 +25,19 @@ require (
github.com/manifoldco/promptui v0.3.2
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.9
github.com/mholt/archiver v3.1.1+incompatible
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/nwaples/rardecode v1.0.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/pierrec/lz4 v2.2.6+incompatible // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/procfs v0.0.5 // indirect
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851
github.com/segmentio/ksuid v1.0.3
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.5.1
github.com/tj/go-spin v1.1.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/ulikunitz/xz v0.5.6 // indirect
go.opencensus.io v0.22.0 // indirect
go.undefinedlabs.com/scopeagent v0.1.7
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
Expand Down