Skip to content

Commit

Permalink
Support custom metrics for air gapped SDK installs (#117)
Browse files Browse the repository at this point in the history
* Support custom metrics for air gapped SDK installs
  • Loading branch information
sgalsaleh authored Nov 6, 2023
1 parent 5503805 commit cf156a3
Show file tree
Hide file tree
Showing 25 changed files with 1,102 additions and 577 deletions.
29 changes: 29 additions & 0 deletions .github/actions/validate-endpoints/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,32 @@ runs:
exit 1
fi
fi
- name: Validate /app/custom-metrics endpoint
shell: bash
run: |
for i in {1..5}
do
string_key=$(shuf -er -n10 {A..Z} {a..z} {0..9} | tr -d '\n')
integer_key=$(shuf -i 1-100 -n 1 | tr -d '\n')
bool_key=true
body='{"data":{"string_key":"'$string_key'","integer_key":'$integer_key',"bool_key":'$bool_key'}}'
curl -XPOST -s --fail --show-error localhost:8888/api/v1/app/custom-metrics -H 'Content-Type: application/json' -d $body
done
if [ "${{ inputs.is-airgap }}" == "false" ]; then
exit 0
fi
if ! kubectl -n "${{ inputs.namespace }}" get secret/replicated-custom-app-metrics-report; then
echo "Did not create replicated-custom-app-metrics-report secret"
exit 1
fi
report=$(kubectl -n "${{ inputs.namespace }}" get secret replicated-custom-app-metrics-report -ojsonpath='{.data.report}' | base64 -d | base64 -d | gunzip | jq .)
numOfEvents=$(echo "$report" | jq '.events | length' | tr -d '\n')
if [ "$numOfEvents" != "5" ]; then
echo "Expected 5 events, but found $numOfEvents"
exit 1
fi
12 changes: 10 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ jobs:
curl -fsLO "https://github.com/replicatedhq/troubleshoot/releases/download/${RELEASE}/support-bundle_linux_amd64.tar.gz"
tar xzf support-bundle_linux_amd64.tar.gz
- name: Install via Helm as subchart in production mode
- name: Install via Helm as subchart in production airgap mode
run: |
helm install test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --set replicated.isAirgap=true --wait --timeout 2m
Expand Down Expand Up @@ -501,6 +501,10 @@ jobs:
echo "Did not find replicated-instance-report in support bundle"
exit 1
fi
if ! ls support-bundle-*/secrets/*/replicated-custom-app-metrics-report/report.json; then
echo "Did not find replicated-custom-app-metrics-report in support bundle"
exit 1
fi
rm -rf support-bundle-*
- name: Uninstall test-chart via Helm
Expand All @@ -517,7 +521,7 @@ jobs:
sleep 1
done
- name: Install via kubectl as subchart in production mode
- name: Install via kubectl as subchart in production airgap mode
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --set replicated.isAirgap=true | kubectl apply -f -
kubectl rollout status deployment test-chart --timeout=2m
Expand Down Expand Up @@ -550,6 +554,10 @@ jobs:
echo "Did not find replicated-instance-report in support bundle"
exit 1
fi
if ! ls support-bundle-*/secrets/*/replicated-custom-app-metrics-report/report.json; then
echo "Did not find replicated-custom-app-metrics-report in support bundle"
exit 1
fi
rm -rf support-bundle-*
- name: Uninstall test-chart via kubectl
Expand Down
1 change: 1 addition & 0 deletions chart/templates/replicated-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ rules:
resourceNames:
- {{ include "replicated.secretName" . }}
- replicated-instance-report
- replicated-custom-app-metrics-report
{{ end }}
5 changes: 5 additions & 0 deletions chart/templates/replicated-supportbundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ stringData:
name: replicated-instance-report
includeValue: true
key: report
- secret:
namespace: {{ include "replicated.namespace" . }}
name: replicated-custom-app-metrics-report
includeValue: true
key: report
analyzers:
- jsonCompare:
checkName: Replicated SDK App Status
Expand Down
10 changes: 5 additions & 5 deletions pact/custom_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestSendCustomAppMetrics(t *testing.T) {
"key4_numeric_string": "1.6",
},
}
customMetricsData, _ := json.Marshal(data)
customAppMetricsData, _ := json.Marshal(data)
license := &v1beta1.License{
Spec: v1beta1.LicenseSpec{
LicenseID: "sdk-license-customer-0-license",
Expand All @@ -40,14 +40,14 @@ func TestSendCustomAppMetrics(t *testing.T) {

clientWriter := httptest.NewRecorder()
clientRequest := &http.Request{
Body: io.NopCloser(bytes.NewBuffer(customMetricsData)),
Body: io.NopCloser(bytes.NewBuffer(customAppMetricsData)),
}

pactInteraction := func() {
pact.
AddInteraction().
Given("Send valid custom metrics").
UponReceiving("A request to send custom metrics").
Given("Send valid custom app metrics").
UponReceiving("A request to send custom app metrics").
WithRequest(dsl.Request{
Method: http.MethodPost,
Headers: dsl.MapMatcher{
Expand All @@ -63,7 +63,7 @@ func TestSendCustomAppMetrics(t *testing.T) {
Status: http.StatusOK,
})
}
t.Run("Send valid custom metrics", func(t *testing.T) {
t.Run("Send valid custom app metrics", func(t *testing.T) {
pactInteraction()

storeOptions := store.InitInMemoryStoreOptions{
Expand Down
Loading

0 comments on commit cf156a3

Please sign in to comment.