Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
183 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
local formatLabels = function(labels) | ||
local lf = std.join(', ', std.map(function(l) '%s="%s"' % [ l, labels[l] ], std.objectFields(labels))); | ||
"{%s}" % [ lf ]; | ||
|
||
local series = function(name, labels, values) { | ||
series: name+formatLabels(labels), | ||
values: values, | ||
}; | ||
|
||
{ | ||
series: series, | ||
formatLabels: formatLabels, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
local c = import 'common.libsonnet'; | ||
|
||
local query = importstr '../appuio_cloud_memory.promql'; | ||
|
||
local commonLabels = { | ||
cluster_id: 'c-appuio-cloudscale-lpg-2', | ||
tenant_id: 'c-appuio-cloudscale-lpg-2', | ||
}; | ||
|
||
{ | ||
tests: [ | ||
{ | ||
interval: '30s', | ||
local runningUID = '35e3a8b1-b46d-496c-b2b7-1b52953bf904', | ||
local succeededUID = '2a7a6e32-0840-4ac3-bab4-52d7e16f4a0a', | ||
input_series: [ | ||
c.series('kube_node_labels', commonLabels { | ||
label_appuio_io_node_class: 'flex', | ||
label_kubernetes_io_hostname: 'flex-x666', | ||
node: 'flex-x666', | ||
}, '1+0x10'), | ||
c.series('kube_namespace_labels', commonLabels { | ||
namespace: 'testproject', | ||
label_appuio_io_organization: 'cherry-pickers-inc', | ||
}, '1+0x10'), | ||
// Phases | ||
c.series('kube_pod_status_phase', commonLabels { | ||
namespace: 'testproject', | ||
phase: 'Succeeded', | ||
pod: 'succeeded-pod', | ||
uid: succeededUID, | ||
}, '1+0x10'), | ||
c.series('kube_pod_status_phase', commonLabels { | ||
namespace: 'testproject', | ||
phase: 'Running', | ||
pod: 'running-pod', | ||
uid: runningUID, | ||
}, '1+0x10'), | ||
// Requests | ||
c.series('kube_pod_container_resource_requests', commonLabels { | ||
namespace: 'testproject', | ||
pod: 'succeeded-pod', | ||
resource: 'memory', | ||
node: 'flex-x666', | ||
uid: succeededUID, | ||
}, '1+0x10'), | ||
c.series('kube_pod_container_resource_requests', commonLabels { | ||
namespace: 'testproject', | ||
pod: 'running-pod', | ||
resource: 'memory', | ||
node: 'flex-x666', | ||
uid: runningUID, | ||
}, '1+0x10'), | ||
c.series('kube_pod_container_resource_requests', commonLabels { | ||
namespace: 'testproject', | ||
pod: 'succeeded-pod', | ||
node: 'flex-x666', | ||
resource: 'cpu', | ||
uid: succeededUID, | ||
}, '0+0x10'), | ||
c.series('kube_pod_container_resource_requests', commonLabels { | ||
namespace: 'testproject', | ||
pod: 'running-pod', | ||
node: 'flex-x666', | ||
resource: 'cpu', | ||
uid: runningUID, | ||
}, '0+0x10'), | ||
// Real usage | ||
c.series('container_memory_working_set_bytes', commonLabels { | ||
image: 'busybox', | ||
namespace: 'testproject', | ||
pod: 'succeeded-pod', | ||
node: 'flex-x666', | ||
uid: succeededUID, | ||
}, '1+0x10'), | ||
c.series('container_memory_working_set_bytes', commonLabels { | ||
image: 'busybox', | ||
namespace: 'testproject', | ||
pod: 'running-pod', | ||
node: 'flex-x666', | ||
uid: runningUID, | ||
}, '1+0x10'), | ||
], | ||
promql_expr_test: [ | ||
{ | ||
expr: query, | ||
eval_time: '1h', | ||
exp_samples: [ | ||
{ | ||
labels: c.formatLabels({ | ||
category: 'c-appuio-cloudscale-lpg-2:testproject', | ||
cluster_id: 'c-appuio-cloudscale-lpg-2', | ||
label_appuio_io_node_class: 'flex', | ||
namespace: 'testproject', | ||
product: 'appuio_cloud_memory:c-appuio-cloudscale-lpg-2:cherry-pickers-inc:testproject:flex', | ||
tenant_id: 'cherry-pickers-inc', | ||
}), | ||
value: 128 * 10, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package seeds_test | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"os/exec" | ||
"path" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-jsonnet" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/appuio/appuio-cloud-reporting/pkg/testsuite" | ||
) | ||
|
||
func TestQueries(t *testing.T) { | ||
wd := os.DirFS(".") | ||
jvm := jsonnet.MakeVM() | ||
|
||
testFiles, err := fs.Glob(wd, "promtest/*.jsonnet") | ||
require.NoError(t, err) | ||
for _, test := range testFiles { | ||
t.Run(test, func(t *testing.T) { | ||
ev, err := jvm.EvaluateFile(test) | ||
require.NoError(t, err) | ||
tmp := path.Join(t.TempDir(), "test.json") | ||
err = os.WriteFile(tmp, []byte(ev), 0644) | ||
require.NoError(t, err) | ||
|
||
cmd := exec.Command(testsuite.PromtoolBin, "test", "rules", tmp) | ||
var stderr, stdout strings.Builder | ||
cmd.Stderr = &stderr | ||
cmd.Stdout = &stdout | ||
assert.NoError(t, cmd.Run()) | ||
// Not using t.Log to keep formatting sane | ||
fmt.Println("STDERR") | ||
fmt.Println(stderr.String()) | ||
fmt.Println("STDOUT") | ||
fmt.Println(stdout.String()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters