Skip to content

Commit

Permalink
ROX-6200 Fix JSON parsing error (#382)
Browse files Browse the repository at this point in the history
Remove consumption labels or env var metadata from container runtime
  • Loading branch information
robbycochran authored Jan 25, 2021
1 parent b4ea768 commit 993e623
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ jobs:
export VM_CONFIG="circle_local_<< parameters.vm-config >>"
export COLLECTOR_REPO="stackrox/collector<<# parameters.use-rhel>>-rhel<</ parameters.use-rhel>>"
export COLLECTOR_IMAGE="${COLLECTOR_REPO}:${COLLECTOR_TAG}"
make -C "${SOURCE_ROOT}" integration-tests-missing-proc-scrape integration-tests integration-tests-report
make -C "${SOURCE_ROOT}" integration-tests-missing-proc-scrape integration-tests-image-label-json integration-tests integration-tests-report
[[ -z "$CIRCLE_BRANCH" ]] || gsutil cp ~/workspace/go/src/github.com/stackrox/collector/integration-tests/integration-test-report.xml "gs://stackrox-ci-results/circleci/collector/${CIRCLE_BRANCH}/$(date +%Y-%m-%d)-${CIRCLE_BUILD_NUM}/"
- store_test_results:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ integration-tests-process-network:
integration-tests-missing-proc-scrape:
make -C integration-tests missing-proc-scrape

.PHONY: integration-tests-image-label-json
integration-tests-image-label-json:
make -C integration-tests image-label-json

.PHONY: integration-tests-process-network-rhel
integration-tests-process-network-rhel:
COLLECTOR_REPO="stackrox/collector-rhel" \
Expand Down
2 changes: 2 additions & 0 deletions collector/container/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,12 @@ function main() {
eval exec "$@" &
PID=$!
wait $PID
status=$?

if collection_method_module; then
remove_module "$module_name"
fi
exit $status
}

main "$@"
7 changes: 7 additions & 0 deletions integration-tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ baseline: docker-clean
go test -timeout 30m -count=1 -v \
-run TestBenchmarkBaseline 2>&1 | tee -a integration-test.log

.PHONY: image-label-json
image-label-json: docker-clean
go version
set -o pipefail ; \
go test -timeout 30m -count=1 -v \
-run TestImageLabelJSON 2>&1 | tee -a integration-test.log

.PHONY: missing-proc-scrape
missing-proc-scrape: docker-clean
./scripts/create-fake-proc-dir.sh
Expand Down
17 changes: 16 additions & 1 deletion integration-tests/collector_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,22 @@ func (c *collectorManager) TearDown() error {
}

c.captureLogs("collector")
c.killContainer("collector")
isRunning, err := c.executor.IsContainerRunning("collector")
if err != nil {
return err
}
if isRunning {
c.killContainer("collector")
} else {
// Check if collector container segfaulted or exited with error
exitCode, err := c.executor.ExitCode("collector")
if err != nil {
return err
}
if exitCode != 0 {
return fmt.Errorf("Collector container has non-zero exit code (%d)", exitCode)
}
}
return nil
}

Expand Down
22 changes: 22 additions & 0 deletions integration-tests/container/jsonlabel/Dockerfile

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion integration-tests/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Executor interface {
CopyFromHost(src string, dst string) (string, error)
PullImage(image string) error
IsContainerRunning(image string) (bool, error)
ExitCode(container string) (int, error)
Exec(args ...string) (string, error)
ExecRetry(args ...string) (string, error)
}
Expand Down Expand Up @@ -167,11 +168,19 @@ func (e *executor) PullImage(image string) error {
func (e *executor) IsContainerRunning(containerID string) (bool, error) {
result, err := e.Exec("docker", "inspect", containerID, "--format='{{.State.Running}}'")
if err != nil {
return false, nil
return false, err
}
return result == "'true'", nil
}

func (e *executor) ExitCode(containerID string) (int, error) {
result, err := e.Exec("docker", "inspect", containerID, "--format='{{.State.ExitCode}}'")
if err != nil {
return -1, err
}
return strconv.Atoi(strings.Trim(result, "\"'"))
}

func (e *localCommandBuilder) ExecCommand(execArgs ...string) *exec.Cmd {
return exec.Command(execArgs[0], execArgs[1:]...)
}
Expand Down
44 changes: 44 additions & 0 deletions integration-tests/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func TestBenchmark(t *testing.T) {
suite.Run(t, new(BenchmarkCollectorTestSuite))
}

func TestImageLabelJSON(t *testing.T) {
suite.Run(t, new(ImageLabelJSONTestSuite))
}

// TestMissingProcScrape only works with local fake proc directory
func TestMissingProcScrape(t *testing.T) {
if ReadEnvVarWithDefault("REMOTE_HOST_TYPE", "local") == "local" {
Expand Down Expand Up @@ -95,6 +99,31 @@ type MissingProcScrapeTestSuite struct {
IntegrationTestSuiteBase
}

type ImageLabelJSONTestSuite struct {
IntegrationTestSuiteBase
}

func (s *ImageLabelJSONTestSuite) SetupSuite() {
s.executor = NewExecutor()
s.collector = NewCollectorManager(s.executor, s.T().Name())
err := s.collector.Setup()
require.NoError(s.T(), err)
err = s.collector.Launch()
require.NoError(s.T(), err)
}

func (s *ImageLabelJSONTestSuite) TestRunImageWithJSONLabel() {
s.RunImageWithJSONLabels()
}

func (s *ImageLabelJSONTestSuite) TearDownSuite() {
err := s.collector.TearDown()
require.NoError(s.T(), err)
s.db, err = s.collector.BoltDB()
require.NoError(s.T(), err)
s.cleanupContainer([]string{"collector", "grpc-server", "jsonlabel"})
}

func (s *BenchmarkCollectorTestSuite) SetupSuite() {
s.executor = NewExecutor()
s.StartContainerStats()
Expand Down Expand Up @@ -483,6 +512,21 @@ func (s *IntegrationTestSuiteBase) RunCollectorBenchmark() {
}
}

func (s *IntegrationTestSuiteBase) RunImageWithJSONLabels() {
name := "jsonlabel"
image := "stackrox/benchmark-collector:json-label"
err := s.executor.PullImage(image)
require.NoError(s.T(), err)
args := []string{
name,
image,
}
containerID, err := s.launchContainer(args...)
require.NoError(s.T(), err)
_, err = s.waitForContainerToExit(name, containerID[0:12])
require.NoError(s.T(), err)
}

func (s *IntegrationTestSuiteBase) StartContainerStats() {
name := "container-stats"
image := "stackrox/benchmark-collector:stats"
Expand Down
2 changes: 1 addition & 1 deletion sysdig/src
Submodule src updated from 62fea2 to 15d93d

0 comments on commit 993e623

Please sign in to comment.