Skip to content

Commit cf156a3

Browse files
authored
Support custom metrics for air gapped SDK installs (#117)
* Support custom metrics for air gapped SDK installs
1 parent 5503805 commit cf156a3

25 files changed

+1102
-577
lines changed

.github/actions/validate-endpoints/action.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,32 @@ runs:
150150
exit 1
151151
fi
152152
fi
153+
154+
- name: Validate /app/custom-metrics endpoint
155+
shell: bash
156+
run: |
157+
for i in {1..5}
158+
do
159+
string_key=$(shuf -er -n10 {A..Z} {a..z} {0..9} | tr -d '\n')
160+
integer_key=$(shuf -i 1-100 -n 1 | tr -d '\n')
161+
bool_key=true
162+
body='{"data":{"string_key":"'$string_key'","integer_key":'$integer_key',"bool_key":'$bool_key'}}'
163+
curl -XPOST -s --fail --show-error localhost:8888/api/v1/app/custom-metrics -H 'Content-Type: application/json' -d $body
164+
done
165+
166+
if [ "${{ inputs.is-airgap }}" == "false" ]; then
167+
exit 0
168+
fi
169+
170+
if ! kubectl -n "${{ inputs.namespace }}" get secret/replicated-custom-app-metrics-report; then
171+
echo "Did not create replicated-custom-app-metrics-report secret"
172+
exit 1
173+
fi
174+
175+
report=$(kubectl -n "${{ inputs.namespace }}" get secret replicated-custom-app-metrics-report -ojsonpath='{.data.report}' | base64 -d | base64 -d | gunzip | jq .)
176+
177+
numOfEvents=$(echo "$report" | jq '.events | length' | tr -d '\n')
178+
if [ "$numOfEvents" != "5" ]; then
179+
echo "Expected 5 events, but found $numOfEvents"
180+
exit 1
181+
fi

.github/workflows/main.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ jobs:
471471
curl -fsLO "https://github.com/replicatedhq/troubleshoot/releases/download/${RELEASE}/support-bundle_linux_amd64.tar.gz"
472472
tar xzf support-bundle_linux_amd64.tar.gz
473473
474-
- name: Install via Helm as subchart in production mode
474+
- name: Install via Helm as subchart in production airgap mode
475475
run: |
476476
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
477477
@@ -501,6 +501,10 @@ jobs:
501501
echo "Did not find replicated-instance-report in support bundle"
502502
exit 1
503503
fi
504+
if ! ls support-bundle-*/secrets/*/replicated-custom-app-metrics-report/report.json; then
505+
echo "Did not find replicated-custom-app-metrics-report in support bundle"
506+
exit 1
507+
fi
504508
rm -rf support-bundle-*
505509
506510
- name: Uninstall test-chart via Helm
@@ -517,7 +521,7 @@ jobs:
517521
sleep 1
518522
done
519523
520-
- name: Install via kubectl as subchart in production mode
524+
- name: Install via kubectl as subchart in production airgap mode
521525
run: |
522526
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 -
523527
kubectl rollout status deployment test-chart --timeout=2m
@@ -550,6 +554,10 @@ jobs:
550554
echo "Did not find replicated-instance-report in support bundle"
551555
exit 1
552556
fi
557+
if ! ls support-bundle-*/secrets/*/replicated-custom-app-metrics-report/report.json; then
558+
echo "Did not find replicated-custom-app-metrics-report in support bundle"
559+
exit 1
560+
fi
553561
rm -rf support-bundle-*
554562
555563
- name: Uninstall test-chart via kubectl

chart/templates/replicated-role.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ rules:
3030
resourceNames:
3131
- {{ include "replicated.secretName" . }}
3232
- replicated-instance-report
33+
- replicated-custom-app-metrics-report
3334
{{ end }}

chart/templates/replicated-supportbundle.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ stringData:
4444
name: replicated-instance-report
4545
includeValue: true
4646
key: report
47+
- secret:
48+
namespace: {{ include "replicated.namespace" . }}
49+
name: replicated-custom-app-metrics-report
50+
includeValue: true
51+
key: report
4752
analyzers:
4853
- jsonCompare:
4954
checkName: Replicated SDK App Status

pact/custom_metrics_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestSendCustomAppMetrics(t *testing.T) {
2828
"key4_numeric_string": "1.6",
2929
},
3030
}
31-
customMetricsData, _ := json.Marshal(data)
31+
customAppMetricsData, _ := json.Marshal(data)
3232
license := &v1beta1.License{
3333
Spec: v1beta1.LicenseSpec{
3434
LicenseID: "sdk-license-customer-0-license",
@@ -40,14 +40,14 @@ func TestSendCustomAppMetrics(t *testing.T) {
4040

4141
clientWriter := httptest.NewRecorder()
4242
clientRequest := &http.Request{
43-
Body: io.NopCloser(bytes.NewBuffer(customMetricsData)),
43+
Body: io.NopCloser(bytes.NewBuffer(customAppMetricsData)),
4444
}
4545

4646
pactInteraction := func() {
4747
pact.
4848
AddInteraction().
49-
Given("Send valid custom metrics").
50-
UponReceiving("A request to send custom metrics").
49+
Given("Send valid custom app metrics").
50+
UponReceiving("A request to send custom app metrics").
5151
WithRequest(dsl.Request{
5252
Method: http.MethodPost,
5353
Headers: dsl.MapMatcher{
@@ -63,7 +63,7 @@ func TestSendCustomAppMetrics(t *testing.T) {
6363
Status: http.StatusOK,
6464
})
6565
}
66-
t.Run("Send valid custom metrics", func(t *testing.T) {
66+
t.Run("Send valid custom app metrics", func(t *testing.T) {
6767
pactInteraction()
6868

6969
storeOptions := store.InitInMemoryStoreOptions{

0 commit comments

Comments
 (0)