Skip to content

Commit

Permalink
STAC-21039: Some more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
craffit committed May 6, 2024
1 parent 057df17 commit 71d56d6
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCheckHandlerNonTransactionalAPI(t *testing.T) {
mockBatcher := batcher.NewMockBatcher()
// sender for non-transactional events
sender := mocksender.NewMockSender(testCheck.ID())
sender.On("Event", mock.AnythingOfType("metrics.Event"))
sender.On("Event", mock.AnythingOfType("event.Event"))

nonTransactionCH.SubmitStartSnapshot(instance)
nonTransactionCH.SubmitComponent(instance, testComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CommonCheck struct {
}

func (k *CommonCheck) ConfigureKubeAPICheck(senderManager sender.SenderManager, integrationConfigDigest uint64, config, initConfig integration.Data, source string) error {
return k.CommonConfigure(senderManager, integrationConfigDigest, config, initConfig, source)
return k.CommonConfigure(senderManager, integrationConfigDigest, initConfig, config, source)
}

func (k *CommonCheck) InitKubeAPICheck() error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func getAlertType(ev *v1.Event) event.EventAlertType {
case "warning":
return event.EventAlertTypeWarning
default:
log.Warnf("Unhandled kubernetes event type '%s', fallback to metrics.EventAlertTypeInfo", ev.Type)
log.Warnf("Unhandled kubernetes event type '%s', fallback to event.EventAlertTypeInfo", ev.Type)
return event.EventAlertTypeInfo
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"context"
"fmt"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/util"
"github.com/DataDog/datadog-agent/pkg/util/hostname"
"strings"
"time"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestProcessPodEvents(t *testing.T) {
evCheck.ac = MockAPIClient(nil)

mockSender := mocksender.NewMockSender(evCheck.ID())
mockSender.On("Event", mock.AnythingOfType("metrics.Event"))
mockSender.On("Event", mock.AnythingOfType("event.Event"))

evCheck.processPods(mockSender, podEvents)
mockSender.AssertNumberOfCalls(t, "Event", 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ package kubeapi
import (
"context"
"fmt"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"github.com/DataDog/datadog-agent/pkg/metrics/event"
"sort"
"testing"
Expand Down Expand Up @@ -333,7 +335,7 @@ event_categories:
DarkMystery: V0ID
EnsuringLoadBalancer: Activities
`
err := evCheck.Configure([]byte(mappingOfCustomEvents), nil, "")
err := evCheck.Configure(aggregator.NewNoOpSenderManager(), integration.FakeConfigHash, []byte(mappingOfCustomEvents), []byte(``), "test")
assert.NoError(t, err)

mockSender := mocksender.NewMockSender(evCheck.ID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (k *MetricsCheck) getClusterName() {

// Configure parses the check configuration and init the check.
func (k *MetricsCheck) Configure(senderManager sender.SenderManager, integrationConfigDigest uint64, config, initConfig integration.Data, source string) error {
err := k.CommonConfigure(senderManager, integrationConfigDigest, config, initConfig, source)
err := k.CommonConfigure(senderManager, integrationConfigDigest, initConfig, config, source)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package kubeapi

import (
"github.com/DataDog/datadog-agent/pkg/metrics/servicecheck"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -15,7 +16,6 @@ import (

"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
core "github.com/DataDog/datadog-agent/pkg/collector/corechecks"
"github.com/DataDog/datadog-agent/pkg/metrics"
)

func TestParseComponentStatus(t *testing.T) {
Expand Down Expand Up @@ -84,25 +84,25 @@ func TestParseComponentStatus(t *testing.T) {
kubeAPIMetricsCheck := NewKubernetesAPIMetricsCheck(core.NewCheckBase(kubernetesAPIMetricsCheckName), &MetricsConfig{})

mocked := mocksender.NewMockSender(kubeAPIMetricsCheck.ID())
mocked.On("ServiceCheck", "kube_apiserver_controlplane.up", metrics.ServiceCheckOK, "", []string{"component:Zookeeper"}, "imok")
mocked.On("ServiceCheck", "kube_apiserver_controlplane.up", servicecheck.ServiceCheckOK, "", []string{"component:Zookeeper"}, "imok")
_ = kubeAPIMetricsCheck.parseComponentStatus(mocked, expected)

mocked.AssertNumberOfCalls(t, "ServiceCheck", 1)
mocked.AssertServiceCheck(t, "kube_apiserver_controlplane.up", metrics.ServiceCheckOK, "", []string{"component:Zookeeper"}, "imok")
mocked.AssertServiceCheck(t, "kube_apiserver_controlplane.up", servicecheck.ServiceCheckOK, "", []string{"component:Zookeeper"}, "imok")

err := kubeAPIMetricsCheck.parseComponentStatus(mocked, unExpected)
assert.EqualError(t, err, "metadata structure has changed. Not collecting API Server's Components status")
mocked.AssertNotCalled(t, "ServiceCheck", "kube_apiserver_controlplane.up")

mocked.On("ServiceCheck", "kube_apiserver_controlplane.up", metrics.ServiceCheckCritical, "", []string{"component:ETCD"}, "Connection closed")
mocked.On("ServiceCheck", "kube_apiserver_controlplane.up", servicecheck.ServiceCheckCritical, "", []string{"component:ETCD"}, "Connection closed")
_ = kubeAPIMetricsCheck.parseComponentStatus(mocked, unHealthy)
mocked.AssertNumberOfCalls(t, "ServiceCheck", 2)
mocked.AssertServiceCheck(t, "kube_apiserver_controlplane.up", metrics.ServiceCheckCritical, "", []string{"component:ETCD"}, "Connection closed")
mocked.AssertServiceCheck(t, "kube_apiserver_controlplane.up", servicecheck.ServiceCheckCritical, "", []string{"component:ETCD"}, "Connection closed")

mocked.On("ServiceCheck", "kube_apiserver_controlplane.up", metrics.ServiceCheckUnknown, "", []string{"component:DCA"}, "")
mocked.On("ServiceCheck", "kube_apiserver_controlplane.up", servicecheck.ServiceCheckUnknown, "", []string{"component:DCA"}, "")
_ = kubeAPIMetricsCheck.parseComponentStatus(mocked, unknown)
mocked.AssertNumberOfCalls(t, "ServiceCheck", 3)
mocked.AssertServiceCheck(t, "kube_apiserver_controlplane.up", metrics.ServiceCheckUnknown, "", []string{"component:DCA"}, "")
mocked.AssertServiceCheck(t, "kube_apiserver_controlplane.up", servicecheck.ServiceCheckUnknown, "", []string{"component:DCA"}, "")

emptyResp := kubeAPIMetricsCheck.parseComponentStatus(mocked, empty)
assert.Nil(t, emptyResp, "metadata structure has changed. Not collecting API Server's Components status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ package kubeapi
import (
"encoding/json"
"fmt"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"io/ioutil"
"testing"

Expand All @@ -29,7 +31,7 @@ func TestReportClusterQuotas(t *testing.T) {
var instanceCfg = []byte("")
var initCfg = []byte("")
kubeAPIMetricsCheck := KubernetesAPIMetricsFactory().(*MetricsCheck)
err = kubeAPIMetricsCheck.Configure(instanceCfg, initCfg, "test")
err = kubeAPIMetricsCheck.Configure(aggregator.NewNoOpSenderManager(), integration.FakeConfigHash, instanceCfg, initCfg, "test")
require.NoError(t, err)

mocked := mocksender.NewMockSender(kubeAPIMetricsCheck.ID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package kubeapi

import (
"fmt"
"github.com/DataDog/datadog-agent/pkg/aggregator"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -52,7 +54,7 @@ cluster_name: mycluster
collect_topology: true
csi_pv_mapper_enabled: true
`
err := check.Configure([]byte(nothingIsDisabledConfig), nil, "")
err := check.Configure(aggregator.NewNoOpSenderManager(), integration.FakeConfigHash, []byte(nothingIsDisabledConfig), nil, "")
check.SetFeatures(features.All())
assert.NoError(t, err)

Expand Down Expand Up @@ -86,7 +88,7 @@ resources:
cronjobs: false
secrets: false
`
err := check.Configure([]byte(allResourcesAreDisabledConfig), nil, "")
err := check.Configure(aggregator.NewNoOpSenderManager(), integration.FakeConfigHash, []byte(allResourcesAreDisabledConfig), nil, "")
check.SetFeatures(features.All())
assert.NoError(t, err)

Expand All @@ -113,7 +115,7 @@ func TestRunClusterCollectors(t *testing.T) {

func testConfigParsed(t *testing.T, input string, expected TopologyConfig) {
check := KubernetesAPITopologyFactory().(*TopologyCheck)
err := check.Configure([]byte(input), []byte(""), "whatever")
err := check.Configure(aggregator.NewNoOpSenderManager(), integration.FakeConfigHash, []byte(input), []byte(""), "whatever")
assert.NoError(t, err)
assert.EqualValues(t, &expected, check.instance)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/python/test_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/DataDog/datadog-agent/pkg/aggregator/mocksender"
"github.com/DataDog/datadog-agent/pkg/aggregator/sender"
"github.com/DataDog/datadog-agent/pkg/autodiscovery/integration"
colCheck "github.com/DataDog/datadog-agent/pkg/collector/check"
"github.com/DataDog/datadog-agent/pkg/diagnose/diagnosis"
colCheck "github.com/StackVista/stackstate-agent/pkg/collector/check"
)

/*
Expand Down
8 changes: 0 additions & 8 deletions pkg/serverless/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ func TestStartEnabledTrueValidConfigValidPath(t *testing.T) {
func TestLoadConfigShouldBeFast(t *testing.T) {
t.Skip("Skipping serverless trace agent test to avoid race condition in tests")
setupTraceAgentTest(t)
timeout := time.After(1 * time.Second)
done := make(chan bool)
go func() {
var agent = &ServerlessTraceAgent{}
agent.Start(true, &LoadConfig{Path: "./testdata/valid.yml"})
defer agent.Stop()
done <- true
}()

startTime := time.Now()
lambdaSpanChan := make(chan *pb.Span)
Expand Down
2 changes: 1 addition & 1 deletion tasks/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ def build(
python_runtimes='3',
arch='x64',
exclude_rtloader=False,
go_mod="vendor",
go_mod="readonly",
windows_sysprobe=False,
cmake_options='',
):
Expand Down
2 changes: 1 addition & 1 deletion tasks/go_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ def test(
skip_linters=False,
save_result_json=None,
rerun_fails=None,
go_mod="mod",
go_mod="readonly",
junit_tar="",
only_modified_packages=False,
):
Expand Down

0 comments on commit 71d56d6

Please sign in to comment.