Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
Signed-off-by: Dale Haiducek <dhaiduce@redhat.com>
  • Loading branch information
dhaiducek committed Nov 10, 2022
1 parent 8b1b3cb commit 2dd7bc9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/kind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jobs:
- name: E2E Tests
run: |
export GOPATH=$(go env GOPATH)
export E2E_TEST_ARGS="--focus-file='case25.*'"
make e2e-test-coverage
- name: Create K8s KinD Cluster to simulate hosted mode - ${{ matrix.kind }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ e2e-test: e2e-dependencies
$(GINKGO) -v --fail-fast --slow-spec-threshold=10s $(E2E_TEST_ARGS) test/e2e

.PHONY: e2e-test-coverage
e2e-test-coverage: E2E_TEST_ARGS = --json-report=report_e2e.json --label-filter="!hosted-mode" --output-dir=.
e2e-test-coverage: E2E_TEST_ARGS = --json-report=report_e2e.json --label-filter="!hosted-mode" --output-dir=. --focus-file='case25.*'
e2e-test-coverage: e2e-run-instrumented e2e-test e2e-stop-instrumented

.PHONY: e2e-test-hosted-mode-coverage
Expand Down
5 changes: 3 additions & 2 deletions controllers/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func init() {
// that aren't duplications, and sets a metric for any related object that is handled by multiple
// policies to the number of policies that currently handles it.
func updateRelatedObjectMetric() {
log.V(3).Info("Updating common_related_objects metric ...")
log.Info("Updating common_related_objects metric ...")
log.Info(fmt.Sprintf("Related object map: %+v", policyRelatedObjectMap))

for relatedObj, policies := range policyRelatedObjectMap {
for _, policy := range policies {
Expand All @@ -91,7 +92,7 @@ func updateRelatedObjectMetric() {

gaugeInstance, err := policyRelatedObjectGauge.GetMetricWithLabelValues(relatedObj, policy)
if err != nil {
log.V(3).Error(err, "Failed to retrieve related object gauge")
log.Error(err, "Failed to retrieve related object gauge")

continue
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func main() {
"A path to an alternative kubeconfig for policy evaluation and enforcement.",
)
pflag.StringVar(
&metricsAddr, "metrics-bind-address", "localhost:8383", "The address the metrics endpoint binds to.",
&metricsAddr, "metrics-bind-address", ":8383", "The address the metrics endpoint binds to.",
)
pflag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
pflag.BoolVar(&enableLeaderElection, "leader-elect", true,
Expand Down
15 changes: 14 additions & 1 deletion test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,30 +256,43 @@ func GetMetrics(metricPatterns ...string) []string {
return []string{err.Error()}
}

GinkgoWriter.Println(podCmd.String())
GinkgoWriter.Println(err)
GinkgoWriter.Println(string(propPodInfo))

var cmd *exec.Cmd

metricFilter := " | grep " + strings.Join(metricPatterns, " | grep ")
metricsCmd := `curl localhost:8383/metrics` + metricFilter

// The pod name is "No" when the response is "No resources found"
propPodName := strings.Split(string(propPodInfo), " ")[0]
if propPodName == "No" {
if propPodName == "No" || propPodName == "" {
// A missing pod could mean the controller is running locally
cmd = exec.Command("bash", "-c", metricsCmd)
} else {
cmd = exec.Command("kubectl", "exec", "-n=open-cluster-management-agent-addon", propPodName, "-c",
"config-policy-controller", "--", "bash", "-c", metricsCmd)
}

GinkgoWriter.Println(cmd.String())
GinkgoWriter.Println(metricsCmd)

matchingMetricsRaw, err := cmd.Output()
if err != nil {
GinkgoWriter.Println(string(matchingMetricsRaw))
GinkgoWriter.Println(err)

if err.Error() == "exit status 1" {
return []string{} // exit 1 indicates that grep couldn't find a match.
}

return []string{err.Error()}
}

GinkgoWriter.Println(metricsCmd)
GinkgoWriter.Println(string(matchingMetricsRaw))

matchingMetrics := strings.Split(strings.TrimSpace(string(matchingMetricsRaw)), "\n")
values := make([]string, len(matchingMetrics))

Expand Down

0 comments on commit 2dd7bc9

Please sign in to comment.