Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into cluster_monitoring_label
Browse files Browse the repository at this point in the history
  • Loading branch information
coleenquadros committed Oct 12, 2023
2 parents 34a020e + 2c47e2b commit b79bcec
Show file tree
Hide file tree
Showing 37 changed files with 1,083 additions and 997 deletions.
8 changes: 5 additions & 3 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
approvers:
- dislbenn
- marcolan018
- ngraham20
- subbarao-meduri
- bjoydeep

- saswatamcode
- philipgough
- douglascamata
reviewers:
- clyang82
- haoqing0110
- morvencao
- songleo
- songleo
- ngraham20
2 changes: 2 additions & 0 deletions REMEDIATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@
- <https://issues.redhat.com/browse/ACM-2750>

### Thu Apr 6 23:33:50 EDT 2023

### Wed Oct 11 01:29:03 EDT 2023
21 changes: 15 additions & 6 deletions cicd-scripts/run-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#set -exo pipefail

set -x

ROOTDIR="$(cd "$(dirname "$0")/.." ; pwd -P)"

SED_COMMAND='sed -i -e'
Expand Down Expand Up @@ -77,22 +79,29 @@ if command -v ginkgo &> /dev/null; then
GINKGO_CMD=ginkgo
else
# just for Prow KinD vm

# uninstall old go version(1.16) and install new version
wget https://go.dev/dl/go1.18.8.linux-amd64.tar.gz
sudo rm -fr /usr/local/go
sudo tar -C /usr/local -xzf go1.18.8.linux-amd64.tar.gz

wget https://go.dev/dl/go1.20.4.linux-amd64.tar.gz
if command -v sudo >/dev/null 2>&1; then
sudo rm -fr /usr/local/go
sudo tar -C /usr/local -xzf go1.20.4.linux-amd64.tar.gz
# else
# rm -fr /usr/local/go
# tar -C /usr/local -xzf go1.20.4.linux-amd64.tar.gz
fi
go install github.com/onsi/ginkgo/ginkgo@latest
GINKGO_CMD="$(go env GOPATH)/bin/ginkgo"
fi

go mod vendor
${GINKGO_CMD} -debug -trace ${GINKGO_FOCUS} -v ${ROOTDIR}/tests/pkg/tests -- -options=${OPTIONSFILE} -v=5

cat ${ROOTDIR}/tests/pkg/tests/results.xml | grep failures=\"0\" | grep errors=\"0\"
if [ $? -ne 0 ]; then
echo "Cannot pass all test cases."
cat ${ROOTDIR}/tests/pkg/tests/results.xml
# The underlying cluster is still deleted. Setting large timeout won't help
# echo "sleeping for 60 min"
# sleep 3600
# echo "waking up from sleep"
exit 1
fi
10 changes: 5 additions & 5 deletions cicd-scripts/setup-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ LATEST_SNAPSHOT="${LATEST_SNAPSHOT%\"}"
if ! command -v kubectl &> /dev/null; then
echo "This script will install kubectl (https://kubernetes.io/docs/tasks/tools/install-kubectl/) on your machine"
if [[ "$(uname)" == "Linux" ]]; then
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/linux/amd64/kubectl
curl -LO https://dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl
elif [[ "$(uname)" == "Darwin" ]]; then
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.21.0/bin/darwin/amd64/kubectl
curl -LO curl -LO "https://dl.k8s.io/release/v1.28.2/bin/darwin/arm64/kubectl"
fi
chmod +x ./kubectl && mv ./kubectl ${ROOTDIR}/bin/kubectl
fi
Expand All @@ -69,11 +69,11 @@ fi
if ! command -v kustomize &> /dev/null; then
echo "This script will install kustomize (sigs.k8s.io/kustomize/kustomize) on your machine"
if [[ "$(uname)" == "Linux" ]]; then
curl -o kustomize_v3.8.7.tar.gz -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.8.7/kustomize_v3.8.7_linux_amd64.tar.gz
curl -o kustomize_v5.1.1.tar.gz -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.1/kustomize_v5.1.1_linux_amd64.tar.gz
elif [[ "$(uname)" == "Darwin" ]]; then
curl -o kustomize_v3.8.7.tar.gz -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv3.8.7/kustomize_v3.8.7_darwin_amd64.tar.gz
curl -o kustomize_v5.1.1.tar.gz -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv5.1.1/kustomize_v5.1.1_darwin_amd64.tar.gz
fi
tar xzvf kustomize_v3.8.7.tar.gz
tar xzvf kustomize_v5.1.1.tar.gz
chmod +x ./kustomize && mv ./kustomize ${ROOTDIR}/bin/kustomize
fi

Expand Down
14 changes: 7 additions & 7 deletions collectors/metrics/pkg/collectrule/evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func New(cfg forwarder.Config) (*Evaluator, error) {
logger: log.With(cfg.Logger, "component", "collectrule/evaluator"),
}

if err := unmarshalCollectorRules(evaluator); err != nil {
if err := unmarshalCollectorRules(&evaluator); err != nil {
return nil, err
}

Expand Down Expand Up @@ -128,7 +128,7 @@ func (e *Evaluator) Reconfigure(cfg forwarder.Config) error {
e.interval = evaluator.interval
e.from = evaluator.from
e.collectRules = evaluator.collectRules
if err = unmarshalCollectorRules(*e); err != nil {
if err = unmarshalCollectorRules(e); err != nil {
return err
}

Expand Down Expand Up @@ -159,7 +159,7 @@ func (e *Evaluator) Run(ctx context.Context) {
}
}

func unmarshalCollectorRules(e Evaluator) error {
func unmarshalCollectorRules(e *Evaluator) error {
rules = []CollectRule{}
for _, ruleStr := range e.collectRules {
rule := &CollectRule{}
Expand Down Expand Up @@ -255,10 +255,10 @@ func evaluateRule(logger log.Logger, r CollectRule, metrics []*clientmodel.Metri
now := time.Now()
pendings := map[uint64]string{}
firings := map[uint64]string{}
for k, _ := range (*pendingRules[r.Name]).triggerTime {
for k := range (*pendingRules[r.Name]).triggerTime {
pendings[k] = ""
}
for k, _ := range (*firingRules[r.Name]).triggerTime {
for k := range (*firingRules[r.Name]).triggerTime {
firings[k] = ""
}
for _, metric := range metrics {
Expand Down Expand Up @@ -307,10 +307,10 @@ func evaluateRule(logger log.Logger, r CollectRule, metrics []*clientmodel.Metri
}
}
}
for k, _ := range pendings {
for k := range pendings {
delete((*pendingRules[r.Name]).triggerTime, k)
}
for k, _ := range firings {
for k := range firings {
if (*firingRules[r.Name]).resolveTime[k] == nil {
(*firingRules[r.Name]).resolveTime[k] = &now
} else if time.Since(*(*firingRules[r.Name]).resolveTime[k]) >= expireDuration {
Expand Down
11 changes: 6 additions & 5 deletions collectors/metrics/pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logger

import (
"fmt"
"os"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
Expand Down Expand Up @@ -34,27 +35,27 @@ func LogLevelFromString(l string) level.Option {

// Log is used to handle the error of logger.Log globally
func Log(log log.Logger, l LogLevel, keyvals ...interface{}) {
errkey := "failover_err_%d"
//errkey := "failover_err_%d"
switch l {
case Debug:
err := level.Debug(log).Log(keyvals...)
if err != nil {
fmt.Sprintf(errkey, err)
fmt.Fprintf(os.Stderr, "Error logging: %v\n", err)
}
case Info:
err := level.Info(log).Log(keyvals...)
if err != nil {
fmt.Sprintf(errkey, err)
fmt.Fprintf(os.Stderr, "Error logging: %v\n", err)
}
case Warn:
err := level.Warn(log).Log(keyvals...)
if err != nil {
fmt.Sprintf(errkey, err)
fmt.Fprintf(os.Stderr, "Error logging: %v\n", err)
}
case Error:
err := level.Error(log).Log(keyvals...)
if err != nil {
fmt.Sprintf(errkey, err)
fmt.Fprintf(os.Stderr, "Error logging: %v\n", err)
}
}
}
13 changes: 6 additions & 7 deletions collectors/metrics/pkg/metricfamily/hypershift_transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/go-kit/kit/log"
hyperv1 "github.com/openshift/hypershift/api/v1alpha1"
clientmodel "github.com/prometheus/client_model/go"
prom "github.com/prometheus/client_model/go"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -38,21 +37,21 @@ type hypershiftTransformer struct {

func NewHypershiftTransformer(l log.Logger, c client.Client, labels map[string]string) (Transformer, error) {

clusters := map[string]string{}
//clusters := map[string]string{}
hClient := c
if hClient == nil {
if os.Getenv("UNIT_TEST") != "true" {
config, err := clientcmd.BuildConfigFromFlags("", "")
if err != nil {
return nil, errors.New("Failed to create the kube config")
return nil, errors.New("failed to create the kube config")
}
s := scheme.Scheme
if err := hyperv1.AddToScheme(s); err != nil {
return nil, errors.New("Failed to add observabilityaddon into scheme")
return nil, errors.New("failed to add observabilityaddon into scheme")
}
hClient, err = client.New(config, client.Options{Scheme: s})
if err != nil {
return nil, errors.New("Failed to create the kube client")
return nil, errors.New("failed to create the kube client")
}
} else {
s := scheme.Scheme
Expand Down Expand Up @@ -94,7 +93,7 @@ func (h *hypershiftTransformer) Transform(family *prom.MetricFamily) (bool, erro
if err != nil {
return false, err
}
overrides := map[string]*clientmodel.LabelPair{
overrides := map[string]*prom.LabelPair{
MANAGEMENT_CLUSTER_LABEL: {Name: &MANAGEMENT_CLUSTER_LABEL, Value: &h.managementCluster},
MANAGEMENT_CLUSTER_ID_LABEL: {Name: &MANAGEMENT_CLUSTER_ID_LABEL, Value: &h.managementClusterID},
CLUSTER_ID_LABEL: {Name: &CLUSTER_ID_LABEL, Value: &id},
Expand Down Expand Up @@ -131,7 +130,7 @@ func getClusterName(h *hypershiftTransformer, id string) (string, error) {
}
clusterName, ok = h.hostedClusters[id]
if !ok {
return "", errors.New(fmt.Sprintf("Failed to find HosteCluster with id: %s", id))
return "", fmt.Errorf("failed to find HosteCluster with id: %s", id)
}
}
return clusterName, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

var (
metricsName = "test_metrics"
idLabel = "_id"
id = "test_id"
metricsName = "test_metrics"
idLabel = "_id"
//id = "test_id"
hostedClusterName = "test-hosted-cluster"
hostedClusterID = "test-hosted-cluster-id"
testLabel = "test_label"
Expand Down
30 changes: 17 additions & 13 deletions collectors/metrics/pkg/metricfamily/whitelist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ func familyWithLabels(name string, labels ...[]*clientmodel.LabelPair) *clientmo
func copyMetric(family *clientmodel.MetricFamily) *clientmodel.MetricFamily {
metric := make([]*clientmodel.Metric, len(family.Metric))
copy(metric, family.Metric)
f := *family
f.Metric = metric
return &f
return &clientmodel.MetricFamily{
Name: family.Name,
Help: family.Help,
Type: family.Type,
Metric: metric,
// Copy other fields as needed
}
}

func setNilMetric(family *clientmodel.MetricFamily, positions ...int) *clientmodel.MetricFamily {
Expand Down Expand Up @@ -68,56 +72,56 @@ func TestAllowlist(t *testing.T) {
}

a := familyWithLabels("A", []*clientmodel.LabelPair{
&clientmodel.LabelPair{
{
Name: strPnt("method"),
Value: strPnt("POST"),
},
})

b := familyWithLabels("B", []*clientmodel.LabelPair{
&clientmodel.LabelPair{
{
Name: strPnt("method"),
Value: strPnt("GET"),
},
})

c := familyWithLabels("C",
[]*clientmodel.LabelPair{
&clientmodel.LabelPair{
{
Name: strPnt("method"),
Value: strPnt("POST"),
},
&clientmodel.LabelPair{
{
Name: strPnt("status"),
Value: strPnt("200"),
},
},
[]*clientmodel.LabelPair{
&clientmodel.LabelPair{
{
Name: strPnt("method"),
Value: strPnt("GET"),
},
&clientmodel.LabelPair{
{
Name: strPnt("status"),
Value: strPnt("200"),
},
},
[]*clientmodel.LabelPair{
&clientmodel.LabelPair{
{
Name: strPnt("method"),
Value: strPnt("POST"),
},
&clientmodel.LabelPair{
{
Name: strPnt("status"),
Value: strPnt("500"),
},
},
[]*clientmodel.LabelPair{
&clientmodel.LabelPair{
{
Name: strPnt("method"),
Value: strPnt("DELETE"),
},
&clientmodel.LabelPair{
{
Name: strPnt("status"),
Value: strPnt("200"),
},
Expand Down
Loading

0 comments on commit b79bcec

Please sign in to comment.