Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Support sb topic subscriptions #59

Merged
merged 24 commits into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b8676a0
[GH-42] Add Service Bus Subscription Count Client
marc-sensenich Nov 18, 2018
a4cc5b9
[GH-42] Add vendor packages for Service Bus
marc-sensenich Nov 18, 2018
ecb3954
fixup! [GH-42] Add vendor packages for Service Bus
marc-sensenich Nov 18, 2018
29eec1d
[GH-42] Add the Service Bus Client to the Provider
marc-sensenich Nov 18, 2018
1512afa
[GH-42] Create Azure External Metric Types Generic
marc-sensenich Nov 18, 2018
99dd44b
fixup! [GH-42] Create Azure External Metric Types Generic
marc-sensenich Nov 18, 2018
417f915
[GH-42] Generate v1alpha2 with Service Bus Config
marc-sensenich Nov 18, 2018
4ee9c5e
[GH-42] Break out clients to use the generic interface and add the fa…
marc-sensenich Jan 23, 2019
2946543
generated client files
jsturtevant Jan 26, 2019
8440c8b
Rename function to match metric provider interface
jsturtevant Jan 26, 2019
0fc5d36
Move to v1alpha2, drop v1alpha1
jsturtevant Feb 1, 2019
f6a129c
fix samples
jsturtevant Feb 1, 2019
b0be5a2
aligned the naming for the metric packages
jsturtevant Feb 2, 2019
39b5350
Set type to azuremonitor to be more explicit
jsturtevant Feb 21, 2019
a64dcdf
Add e2e tests for service bus topic subs
jsturtevant Mar 16, 2019
929f241
only gen messages for given subscription
jsturtevant Mar 26, 2019
c1d305a
fail build if any tests fail
jsturtevant Mar 26, 2019
f6459e4
note that topic with a subscription is needed
jsturtevant May 21, 2019
bdf5e5c
add env variables
jsturtevant May 21, 2019
7b8b192
Update configure-topic-subscriptions-metrics.sh
jsturtevant May 21, 2019
8c6ba38
Update run-topic-consumer.sh
jsturtevant May 21, 2019
a33f99c
pin to gen tool to specific version
jsturtevant Jun 28, 2019
9a93060
Fix code gen-issue by pinning
jsturtevant Jun 28, 2019
d00f369
Merge branch 'master' into support-sb-topic-subscriptions
jsturtevant Jun 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .azdevops/image-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,22 @@ jobs:
strategy:
matrix:
K8s10:
SERVICEBUS_SUBSCRIPTION_NAME: 'externalsub-10'
SERVICEBUS_QUEUE_NAME: 'externalq-10'
DOCKER_VERSION: '18.06.1~ce~3-0~ubuntu'
KUBERNETES_VERSION: '1.10.12'
K8s11:
SERVICEBUS_SUBSCRIPTION_NAME: 'externalsub-11'
SERVICEBUS_QUEUE_NAME: 'externalq-11'
DOCKER_VERSION: '17.03.3~ce-0~ubuntu-xenial'
KUBERNETES_VERSION: '1.11.6'
K8s12:
SERVICEBUS_SUBSCRIPTION_NAME: 'externalsub-12'
SERVICEBUS_QUEUE_NAME: 'externalq-12'
DOCKER_VERSION: '18.06.1~ce~3-0~ubuntu'
KUBERNETES_VERSION: '1.12.4'
K8s13:
SERVICEBUS_SUBSCRIPTION_NAME: 'externalsub-13'
SERVICEBUS_QUEUE_NAME: 'externalq-13'
DOCKER_VERSION: '18.06.1~ce~3-0~ubuntu'
KUBERNETES_VERSION: '1.13.1'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,5 @@ typings/
# Serverless directories
.serverless
local-dev-values.yaml

.circleci
20 changes: 19 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,25 @@ To run `make teste2e`, you need the following:

jsturtevant marked this conversation as resolved.
Show resolved Hide resolved
#### Environment variables for e2e tests

Edit the [local dev values](local-dev-values.yaml.example) file to create `local-dev-values.yaml`.
Build the project with a custom repository:

```
make build
```

Edit the [local dev values](local-dev-values.yaml.example) file to create `local-dev-values.yaml`. If using custom image be sure to set the values (`export REGISTRY=<your registry name>` ("" if using DockerHub)
`export IMAGE=azure-k8s-metrics-adapter-testimage`) before building. The `pullPolicy: IfNotPresent` lets you use the local image on your minikube cluster. If you are not using a local cluster you can use `pullPolicy: Always` to use an image that is in a remote repository.

Example of the `image` setting in the `local-dev-values.yaml` using a custom image:

```
image:
repository: metrics-adapter
tag: latest
pullPolicy: IfNotPresent
```

Set the following Environment Variables:
jsturtevant marked this conversation as resolved.
Show resolved Hide resolved

| Variable name | Description | Optional? |
| ------------- | ----------- | --------- |
Expand Down
4 changes: 3 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions charts/azure-k8s-metrics-adapter/templates/apis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
spec:
# group name to use for REST API: /apis/<group>/<version>
group: azure.com
version: v1alpha1
version: v1alpha2
scope: Namespaced
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
Expand All @@ -25,7 +25,7 @@ metadata:
spec:
# group name to use for REST API: /apis/<group>/<version>
group: azure.com
version: v1alpha1
version: v1alpha2
scope: Namespaced
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
Expand Down
4 changes: 2 additions & 2 deletions deploy/adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
spec:
# group name to use for REST API: /apis/<group>/<version>
group: azure.com
version: v1alpha1
version: v1alpha2
scope: Namespaced
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
Expand All @@ -49,7 +49,7 @@ metadata:
spec:
# group name to use for REST API: /apis/<group>/<version>
group: azure.com
version: v1alpha1
version: v1alpha2
scope: Namespaced
names:
# plural name to be used in the URL: /apis/<group>/<version>/<plural>
Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions hack/e2e-scripts/configure-topic-subscriptions-metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -o nounset
set -o errexit

GOPATH="${GOPATH:-$HOME/go}"
SERVICEBUS_TOPIC_NAME="${SERVICEBUS_TOPIC_NAME:-example-topic}"
SERVICEBUS_SUBSCRIPTION_NAME="${SERVICEBUS_SUBSCRIPTION_NAME:-externalsub}"

echo; echo "Configuring external metric (queuemessages)..."
jsturtevant marked this conversation as resolved.
Show resolved Hide resolved
cd $GOPATH/src/github.com/Azure/azure-k8s-metrics-adapter/samples/resources/externalmetric-examples/
cp servicebussubscription-example.yaml servicebussubscription-example.yaml.copy

sed -i 's|sb-external-ns|'${SERVICEBUS_NAMESPACE}'|g' servicebussubscription-example.yaml
sed -i 's|sb-external-example|'${SERVICEBUS_RESOURCE_GROUP}'|g' servicebussubscription-example.yaml
sed -i 's|example-topic|'${SERVICEBUS_TOPIC_NAME}'|g' servicebussubscription-example.yaml
sed -i 's|example-sub|'${SERVICEBUS_SUBSCRIPTION_NAME}'|g' servicebussubscription-example.yaml
kubectl apply -f servicebussubscription-example.yaml

rm servicebussubscription-example.yaml; mv servicebussubscription-example.yaml.copy servicebussubscription-example.yaml
Empty file modified hack/e2e-scripts/deploy-adapter-with-sp.sh
100644 → 100755
Empty file.
19 changes: 3 additions & 16 deletions hack/e2e-scripts/gen-and-check-messages.sh → ...e-scripts/gen-and-check-queue-messages.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@ SERVICEBUS_QUEUE_NAME="${SERVICEBUS_QUEUE_NAME:-externalq}"

cd $GOPATH/src/github.com/Azure/azure-k8s-metrics-adapter/samples/servicebus-queue/

# Copy original files
cp producer/main.go producer/main.go.copy
cp consumer/main.go consumer/main.go.copy

echo; echo "Creating random number for producer script..."
NUM=$(( ($RANDOM % 30 ) + 1 ))
sed -i 's|20000|'$(( NUM + 1 ))'|g' producer/main.go

echo; echo "Replacing queue name in consumer and producer..."
sed -i 's|externalq|'${SERVICEBUS_QUEUE_NAME}'|g' consumer/main.go
sed -i 's|externalq|'${SERVICEBUS_QUEUE_NAME}'|g' producer/main.go

echo; echo "Building producer and consumer..."
make

echo; echo "Returning producer and consumer files to original state..."
rm producer/main.go; mv producer/main.go.copy producer/main.go
rm consumer/main.go; mv consumer/main.go.copy consumer/main.go
echo; echo "Creating random number for producer..."
NUM=$(( ($RANDOM % 30 ) + 1 ))

echo; echo "Sending $NUM messages..."
./bin/producer 0 > /dev/null
./bin/producer 0 $NUM $SERVICEBUS_QUEUE_NAME> /dev/null

echo; echo "Checking metrics endpoint for 4 minutes..."

Expand Down
37 changes: 37 additions & 0 deletions hack/e2e-scripts/gen-and-check-topic-subscriptions-messages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -o nounset
set -o errexit

GOPATH="${GOPATH:-$HOME/go}"
SERVICEBUS_TOPIC_NAME="${SERVICEBUS_TOPIC_NAME:-example-topic}"
SERVICEBUS_SUBSCRIPTION_NAME="${SERVICEBUS_SUBSCRIPTION_NAME:-externalsub}"

cd $GOPATH/src/github.com/Azure/azure-k8s-metrics-adapter/samples/servicebus-topic/

echo; echo "Building producer and consumer..."
make

echo; echo "Creating random number for producer script..."
NUM=$(( ($RANDOM % 30 ) + 1 ))

echo; echo "Sending $NUM messages..."
./bin/producer 0 $NUM $SERVICEBUS_TOPIC_NAME $SERVICEBUS_SUBSCRIPTION_NAME > /dev/null

echo; echo "Checking metrics endpoint for 4 minutes..."

MSGCOUNT=$(kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/example-external-metric-service-bus-subscription" | jq .items[0].value)
START=`date +%s`

while [[ ! "$MSGCOUNT" = "\"$NUM\"" ]] && [[ $(( $(date +%s) - 225 )) -lt $START ]]; do
sleep 15
MSGCOUNT=$(kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/example-external-metric-service-bus-subscription" | jq .items[0].value)
echo "Endpoint returned $MSGCOUNT messages"
done

if [[ ! "$MSGCOUNT" = "\"$NUM\"" ]]; then
echo "Timed out, message count ($MSGCOUNT) not equal to number of messages sent ($NUM)"
exit 1
else
echo "Message count equal to number of messages sent, metrics adapter working correctly"
fi
6 changes: 4 additions & 2 deletions hack/e2e-scripts/run-consumer.sh → hack/e2e-scripts/run-queue-consumer.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
set -o nounset

GOPATH="${GOPATH:-$HOME/go}"
SERVICEBUS_QUEUE_NAME="${SERVICEBUS_QUEUE_NAME:-externalq}"

echo; echo "Running queue consumer to clear queue"
cd $GOPATH/src/github.com/Azure/azure-k8s-metrics-adapter/samples/servicebus-queue/

timeout 30 ./bin/consumer > /dev/null
timeout 30 ./bin/consumer $SERVICEBUS_QUEUE_NAME> /dev/null

# Exit status 124 just means timeout completed, which is what we expect
if [[ $? = 124 ]]; then
echo "Consumer timed out as expected"
exit 0
fi
fi

20 changes: 20 additions & 0 deletions hack/e2e-scripts/run-topic-consumer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

set -o nounset

GOPATH="${GOPATH:-$HOME/go}"

SERVICEBUS_TOPIC_NAME="${SERVICEBUS_TOPIC_NAME:-example-topic}"
SERVICEBUS_SUBSCRIPTION_NAME="${SERVICEBUS_SUBSCRIPTION_NAME:-externalsub}"

echo; echo "Running queue consumer to clear queue"
jsturtevant marked this conversation as resolved.
Show resolved Hide resolved
cd $GOPATH/src/github.com/Azure/azure-k8s-metrics-adapter/samples/servicebus-topic/

timeout 30 ./bin/consumer $SERVICEBUS_TOPIC_NAME $SERVICEBUS_SUBSCRIPTION_NAME> /dev/null

# Exit status 124 just means timeout completed, which is what we expect
if [[ $? = 124 ]]; then
echo "Consumer timed out as expected"
exit 0
fi

25 changes: 20 additions & 5 deletions hack/run-e2e.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,35 @@ echo; echo "Running deployment scripts"
cd $GOPATH/src/github.com/Azure/azure-k8s-metrics-adapter/hack/e2e-scripts
chmod +x *.sh

TEST_FAILED=0

./deploy-adapter-with-sp.sh
if [[ $? = 0 ]]; then
./configure-metrics.sh
echo "Testing Queue (Azure Monitor) metrics"
./configure-queue-metrics.sh
./gen-and-check-queue-messages.sh
if [[ $? = 0 ]];
then echo $DIVIDER; echo "PASS"; echo $DIVIDER
else echo $DIVIDER; echo "FAIL"; echo $DIVIDER; TEST_FAILED=1;
fi

echo "Testing deployment"
./run-queue-consumer.sh

./gen-and-check-messages.sh
echo "Testing Topic Subscriptions metrics"
./configure-topic-subscriptions-metrics.sh
./gen-and-check-topic-subscriptions-messages.sh
if [[ $? = 0 ]];
then echo $DIVIDER; echo "PASS"; echo $DIVIDER
else echo $DIVIDER; echo "FAIL"; echo $DIVIDER;
else echo $DIVIDER; echo "FAIL"; echo $DIVIDER; TEST_FAILED=1;
fi

./run-consumer.sh
./run-topic-consumer.sh
fi

echo "Removing adapter deployment"
helm delete --purge adapter

if [[ $TEST_FAILED == 1 ]]; then
echo $DIVIDER; echo "FAIL"; echo $DIVIDER;
exit 1
fi
2 changes: 1 addition & 1 deletion hack/update-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ set -o pipefail
$GOPATH/src/k8s.io/code-generator/generate-groups.sh all \
github.com/Azure/azure-k8s-metrics-adapter/pkg/client \
github.com/Azure/azure-k8s-metrics-adapter/pkg/apis \
metrics:v1alpha1
metrics:v1alpha2
25 changes: 13 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@ import (
"runtime"
"time"

"github.com/Azure/azure-k8s-metrics-adapter/pkg/azure/appinsights"

"github.com/Azure/azure-k8s-metrics-adapter/pkg/azure/custommetrics"
"github.com/Azure/azure-k8s-metrics-adapter/pkg/azure/externalmetrics"
"github.com/Azure/azure-k8s-metrics-adapter/pkg/azure/instancemetadata"
"github.com/Azure/azure-k8s-metrics-adapter/pkg/azure/monitor"
"github.com/Azure/azure-k8s-metrics-adapter/pkg/metriccache"

clientset "github.com/Azure/azure-k8s-metrics-adapter/pkg/client/clientset/versioned"
informers "github.com/Azure/azure-k8s-metrics-adapter/pkg/client/informers/externalversions"
"github.com/Azure/azure-k8s-metrics-adapter/pkg/controller"
"github.com/Azure/azure-k8s-metrics-adapter/pkg/metriccache"
azureprovider "github.com/Azure/azure-k8s-metrics-adapter/pkg/provider"
"github.com/golang/glog"
basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
Expand Down Expand Up @@ -67,10 +65,13 @@ func setupAzureProvider(cmd *basecmd.AdapterBase, metricsCache *metriccache.Metr
}

defaultSubscriptionID := getDefaultSubscriptionID()
monitorClient := monitor.NewClient(defaultSubscriptionID)
appinsightsClient := appinsights.NewClient()
customMetricsClient := custommetrics.NewClient()

azureExternalClientFactory := externalmetrics.AzureExternalMetricClientFactory{
DefaultSubscriptionID: defaultSubscriptionID,
}

azureProvider := azureprovider.NewAzureProvider(defaultSubscriptionID, mapper, dynamicClient, appinsightsClient, monitorClient, metricsCache)
azureProvider := azureprovider.NewAzureProvider(defaultSubscriptionID, mapper, dynamicClient, customMetricsClient, azureExternalClientFactory, metricsCache)
cmd.WithCustomMetrics(azureProvider)
cmd.WithExternalMetrics(azureProvider)
}
Expand All @@ -86,12 +87,12 @@ func newController(cmd *basecmd.AdapterBase, metricsCache *metriccache.MetricCac
}

adapterInformerFactory := informers.NewSharedInformerFactory(adapterClientSet, time.Second*30)
handler := controller.NewHandler(adapterInformerFactory.Azure().V1alpha1().ExternalMetrics().Lister(),
adapterInformerFactory.Azure().V1alpha1().CustomMetrics().Lister(),
handler := controller.NewHandler(adapterInformerFactory.Azure().V1alpha2().ExternalMetrics().Lister(),
adapterInformerFactory.Azure().V1alpha2().CustomMetrics().Lister(),
metricsCache)

controller := controller.NewController(adapterInformerFactory.Azure().V1alpha1().ExternalMetrics(),
adapterInformerFactory.Azure().V1alpha1().CustomMetrics(), &handler)
controller := controller.NewController(adapterInformerFactory.Azure().V1alpha2().ExternalMetrics(),
adapterInformerFactory.Azure().V1alpha2().CustomMetrics(), &handler)

return controller, adapterInformerFactory
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package v1alpha1
package v1alpha2

import (
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/metrics/v1alpha1/doc.go → pkg/apis/metrics/v1alpha2/doc.go
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +k8s:deepcopy-gen=package
// +groupName=azure.com

package v1alpha1
package v1alpha2
Loading