Skip to content

Commit

Permalink
Begin unit testing jsonnet microservices (#2229)
Browse files Browse the repository at this point in the history
* Attempt unit testing jsonnet microservices

Signed-off-by: Zach Leslie <[email protected]>

* Config update

* Update structure for microservices test

* Wire up CI to run the jsonnet tests

* Separate compile step, use output in first test

---------

Signed-off-by: Zach Leslie <[email protected]>
  • Loading branch information
zalegrala authored Jun 7, 2023
1 parent ad6532f commit ab59010
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jobs:
- name: Check vendor
run: make vendor-check

tempo-mixin:
tempo-jsonnet:
name: Check jsonnet & tempo-mixin
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -227,6 +227,9 @@ jobs:
- name: Check tempo-mixin
run: make tempo-mixin-check

- name: Test jsonnet
run: make jsonnet-test

build-technical-documentation:
name: Build technical documentation
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,15 @@ docs-test:
docker run -v ${PWD}/docs/sources/tempo:/hugo/content/docs/tempo/latest:z -p 3002:3002 --rm $(DOCS_IMAGE) /bin/bash -c 'mkdir -p content/docs/grafana/latest/ && touch content/docs/grafana/latest/menu.yaml && make prod'

### jsonnet
.PHONY: jsonnet jsonnet-check
.PHONY: jsonnet jsonnet-check jsonnet-test
jsonnet:
$(MAKE) -C operations/jsonnet-compiled/util gen

jsonnet-check:
$(MAKE) -C operations/jsonnet-compiled/util check

jsonnet-test:
$(MAKE) -C operations/jsonnet/microservices test

### serverless
.PHONY: docker-serverless test-serverless
Expand Down
16 changes: 16 additions & 0 deletions operations/jsonnet/microservices/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: test
test: jsonnet-compile jsonnet-test tanka-test

tanka-test:
tk show test/environments/default

jsonnet-compile:
@cd test/ && \
mkdir -p outputs && \
jb install && \
jsonnet -J vendor -J lib -o outputs/base.json environments/default/main.jsonnet

jsonnet-test: jsonnet-compile
@cd test/ && \
jsonnet -J vendor -J lib test1.jsonnet

2 changes: 1 addition & 1 deletion operations/jsonnet/microservices/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest

# Initialise the Tanka.
mkdir jsonnet-example && cd jsonnet-example
tk init --k8s=1.21
tk init --k8s=1.26

# Install Tempo jsonnet.
jb install github.com/grafana/tempo/operations/jsonnet/microservices@main
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
local tempo = import '../../../tempo.libsonnet';

tempo {
_images+:: {
// images can be overridden here if desired
},

_config+:: {
cluster: 'k3d',
namespace: 'default',
compactor+: {
},
querier+: {
},
ingester+: {
pvc_size: '5Gi',
pvc_storage_class: 'local-path',
},
distributor+: {
receivers: {
opencensus: null,
jaeger: {
protocols: {
thrift_http: null,
},
},
},
},
metrics_generator+: {
ephemeral_storage_limit_size: '2Gi',
ephemeral_storage_request_size: '1Gi',
},
memcached+: {
replicas: 1,
},
vulture+: {
replicas: 0,
// Disable search until release
tempoSearchBackoffDuration: '0s',
},
backend: 's3',
bucket: 'tempo',
tempo_query_url: 'http://query-frontend:3200',

overrides_configmap_name: 'tempo-overrides',
overrides+:: {},
},

// manually overriding to get tempo to talk to minio
tempo_config+:: {
storage+: {
trace+: {
s3+: {
endpoint: 'minio:9000',
access_key: 'tempo',
secret_key: 'supersecret',
insecure: true,
},
},
},
},

local k = import 'ksonnet-util/kausal.libsonnet',
local service = k.core.v1.service,
tempo_service:
k.util.serviceFor($.tempo_distributor_deployment)
+ service.mixin.metadata.withName('tempo'),

local container = k.core.v1.container,
local containerPort = k.core.v1.containerPort,
tempo_compactor_container+::
k.util.resourcesRequests('500m', '500Mi'),

tempo_distributor_container+::
k.util.resourcesRequests('500m', '500Mi') +
container.withPortsMixin([
containerPort.new('opencensus', 55678),
containerPort.new('jaeger-http', 14268),
]),

tempo_ingester_container+::
k.util.resourcesRequests('500m', '500Mi'),

// clear affinity so we can run multiple ingesters on a single node
tempo_ingester_statefulset+: {
spec+: {
template+: {
spec+: {
affinity: {},
},
},
},
},

tempo_querier_container+::
k.util.resourcesRequests('500m', '500Mi'),

tempo_query_frontend_container+::
k.util.resourcesRequests('300m', '500Mi'),

// clear affinity so we can run multiple instances of memcached on a single node
memcached_all+: {
statefulSet+: {
spec+: {
template+: {
spec+: {
affinity: {},
},
},
},
},
},

local ingress = k.networking.v1.ingress,
local rule = k.networking.v1.ingressRule,
local path = k.networking.v1.httpIngressPath,
ingress:
ingress.new('ingress') +
ingress.mixin.metadata
.withAnnotationsMixin({
'ingress.kubernetes.io/ssl-redirect': 'false',
}) +
ingress.mixin.spec.withRules(
rule.http.withPaths([
path.withPath('/')
+ path.withPathType('ImplementationSpecific')
+ path.backend.service.withName('grafana')
+ path.backend.service.port.withNumber(3000),
]),
),


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"apiVersion": "tanka.dev/v1alpha1",
"kind": "Environment",
"metadata": {
"name": "environments/default"
},
"spec": {
"namespace": "default",
"resourceDefaults": {},
"expectVersions": {}
}
}
51 changes: 51 additions & 0 deletions operations/jsonnet/microservices/test/jsonnetfile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"version": 1,
"dependencies": [
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "ksonnet-util"
}
},
"version": "master"
},
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "memcached"
}
},
"version": "master"
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/docsonnet.git",
"subdir": "doc-util"
}
},
"version": "master"
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/k8s-libsonnet.git",
"subdir": "1.26"
}
},
"version": "main"
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/testonnet.git",
"subdir": ""
}
},
"version": "master"
}
],
"legacyImports": true
}
66 changes: 66 additions & 0 deletions operations/jsonnet/microservices/test/jsonnetfile.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"version": 1,
"dependencies": [
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "ksonnet-util"
}
},
"version": "3b08e7d37511dfd39af6027d07788a5ca8ec71b1",
"sum": "0y3AFX9LQSpfWTxWKSwoLgbt0Wc9nnCwhMH2szKzHv0="
},
{
"source": {
"git": {
"remote": "https://github.com/grafana/jsonnet-libs.git",
"subdir": "memcached"
}
},
"version": "3b08e7d37511dfd39af6027d07788a5ca8ec71b1",
"sum": "SWywAq4U0MRPMbASU0Ez8O9ArRNeoZzb75sEuReueow="
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/docsonnet.git",
"subdir": "doc-util"
}
},
"version": "ff76f6d8edde6366c6dcf81a356481b0e344566b",
"sum": "OxjkWDF0oHmwV52hhyoFW3bwtwgke8s/EOPNRiICPTI="
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/k8s-libsonnet.git",
"subdir": "1.26"
}
},
"version": "a0779420abf73f90167d449a9e527319ced7d134",
"sum": "q6ZaBe1Ciob0O3QbLqtEfOnCGt5rsv5A9RCFN3+Ex/I="
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/testonnet.git",
"subdir": ""
}
},
"version": "9b30f882132b8d8754535fbcee822b804c90405f",
"sum": "MB1dww51rdYJTWAAFkrOXMeMNxzZ5yyFPjPxaERDb1k="
},
{
"source": {
"git": {
"remote": "https://github.com/jsonnet-libs/xtd.git",
"subdir": ""
}
},
"version": "3e494e02563b9eababbb24f0dfca0a50e03dc0b3",
"sum": "GP6SaIzrnD0HRw/EeI3iO9HboA2dnBizgEpxw3m7Ph4="
}
],
"legacyImports": false
}
1 change: 1 addition & 0 deletions operations/jsonnet/microservices/test/lib/k.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'github.com/jsonnet-libs/k8s-libsonnet/1.26/main.libsonnet'
12 changes: 12 additions & 0 deletions operations/jsonnet/microservices/test/test1.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local default = import 'environments/default/main.jsonnet';
local base = import 'outputs/base.json';
local test = import 'testonnet/main.libsonnet';

test.new(std.thisFile)
+ test.case.new(
'Basic',
test.expect.eq(
default,
base
)
)

0 comments on commit ab59010

Please sign in to comment.