Skip to content

Commit

Permalink
Telemetry: E2E tests + VirtualNode scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 authored and adamjensenbot committed Aug 21, 2023
1 parent 3715d0d commit b671739
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ E2E_TARGETS = e2e-dir \
ctl \
e2e-infra \
installer/liqoctl/setup \
telemetry \
installer/liqoctl/peer \
e2e/postinstall \
e2e/cruise \
Expand Down Expand Up @@ -239,5 +240,8 @@ e2e-infra:
installer/%:
${PWD}/test/e2e/pipeline/$@.sh

telemetry:
${PWD}/test/e2e/pipeline/telemetry/telemetry.sh

e2e/%:
go test ${PWD}/test/$@/... -count=1 -timeout=20m
12 changes: 11 additions & 1 deletion cmd/telemetry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"context"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
Expand All @@ -30,12 +31,14 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"

discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
netv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
virtualkubeletv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
offloadingv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1"
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
netv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
"github.com/liqotech/liqo/pkg/consts"
"github.com/liqotech/liqo/pkg/telemetry"
argsutils "github.com/liqotech/liqo/pkg/utils/args"
"github.com/liqotech/liqo/pkg/utils/json"
"github.com/liqotech/liqo/pkg/utils/mapper"
"github.com/liqotech/liqo/pkg/utils/restcfg"
)
Expand All @@ -48,6 +51,7 @@ func init() {
_ = offloadingv1alpha1.AddToScheme(scheme)
_ = sharingv1alpha1.AddToScheme(scheme)
_ = netv1alpha1.AddToScheme(scheme)
_ = virtualkubeletv1alpha1.AddToScheme(scheme)
}

// cluster-role
Expand All @@ -65,6 +69,7 @@ func main() {
namespace := flag.String("namespace", "liqo", "the namespace where liqo is deployed")
liqoVersion := flag.String("liqo-version", "", "the liqo version")
kubernetesVersion := flag.String("kubernetes-version", "", "the kubernetes version")
dryRun := flag.Bool("dry-run", false, "if true, do not send the telemetry item and print it on stdout")
flag.Var(&clusterLabels, consts.ClusterLabelsParameter,
"The set of labels which characterizes the local cluster when exposed remotely as a virtual node")

Expand Down Expand Up @@ -104,6 +109,11 @@ func main() {
os.Exit(1)
}

if *dryRun {
klog.Infof("dry-run enabled, telemetry item:")
fmt.Println(json.Pretty(telemetryItem))
return
}
err = telemetry.Send(ctx, *telemetryEndpoint, telemetryItem, *timeout)
if err != nil {
klog.Errorf("failed to send telemetry item: %v", err)
Expand Down
16 changes: 16 additions & 0 deletions pkg/utils/json/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package json contains some utilities to work with JSON.
package json
26 changes: 26 additions & 0 deletions pkg/utils/json/json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2019-2023 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package json

import "encoding/json"

// Pretty returns an indented JSON string to print.
func Pretty(data interface{}) (string, error) {
val, err := json.MarshalIndent(data, "", " ")
if err != nil {
return "", err
}
return string(val), nil
}
24 changes: 24 additions & 0 deletions test/e2e/pipeline/telemetry/telemetry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# This scripts expects the following variables to be set:
# CLUSTER_NUMBER -> the number of liqo clusters
# NAMESPACE -> the namespace where liqo is running
# LIQO_VERSION -> the liqo version to test
# K8S_VERSION -> the Kubernetes version

set -e # Fail in case of error
set -o nounset # Fail if undefined variables are used
set -o pipefail # Fail if one of the piped commands fails

error() {
local sourcefile=$1
local lineno=$2
echo "An error occurred at $sourcefile:$lineno."
}
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

for i in $(seq 1 "${CLUSTER_NUMBER}")
do
export KUBECONFIG="${TMPDIR2}/kubeconfigs/liqo_kubeconf_${i}"
go run ./cmd/telemetry/main.go --liqo-version "${LIQO_VERSION}" --kubernetes-version "${K8S_VERSION}" --dry-run
done

0 comments on commit b671739

Please sign in to comment.