Uploading your API usage to the IBM License Service
After retrieving the number of API calls made, upload the count to the IBM License Service to store and track your API usage.
Before you begin
Ensure you have the IBM License Service installed before continuing. You can check whether the License Service is installed on the cluster or not using the instructions in Verifying completeness of license usage data. If the service is not installed, see the instructions in Deploying License Service.
Procedure
To upload the number of API calls to the License Service, you can retrieve the details, create the payload, and post the details manually, or you can create a script and run it against the namespace where your API Connect instance is installed.
Retrieving and uploading details manually
Retrieve the upload token from the License Service as follows:
oc get secret ibm-licensing-upload-token -n ibm-common-services -o=jsonpath="{.data.token-upload}" | base64 --decode
Retrieve the metadata annotations from the
analytics-storage
pod that was previously used to obtain the number of API calls:oc describe pod <analytics-storage-pod-name>
Check the contents described in the
metadata.annotations
section, and create the payload for your data upload by copying and pasting the details into a JSON file as follows:{ "cloudpakId": "<enter-value>", "cloudpakName": "<enter-value>", "cloudpakMetric": "RESOURCE_VALUE_UNIT", "productId": "<enter-value>", "productName": "<enter-value>", "productMetric": "MONTHLY_API_CALL", "productCloudpakRatio": "<enter-value>", "metricValue": <enter-your-number-of-api-calls>, "aggregationPolicy": "ADD" }
Run the following command against the
analytics-storage
pod and post the payload you created in the previous step to the License Service:kubectl exec -it <analytics-storage-pod-name> -- \ curl -k -X POST -H 'Content-Type: application/json' -i 'https://ibm-licensing-service-instance.ibm-common-services.svc.cluster.local:8080/v2/metric_upload?token=<upload_token>' --data <payload>
Retrieving and uploading details with a script
Alternatively, if you install jq, you can create a script to complete these steps by saving the following to a shell script and running it as follows:
Save the following as a shell script, for example,
my-upload-script.sh
:#!/bin/bash NAMESPACE=$1 CALLS=$2 TOKEN=$(kubectl get secret ibm-licensing-upload-token -n ibm-common-services -o json | jq -r '.data."token-upload" | @base64d') POD=$(kubectl get po -n $NAMESPACE -o custom-columns=NAME:.metadata.name | grep -e "storage-master-0" | head -n 1) PAYLOAD=$(kubectl get po $POD -n $NAMESPACE -o json | jq --arg CALLS "$CALLS" '.metadata.annotations | { cloudpakId: .cloudpakId, cloudpakName: .cloudpakName, cloudpakMetric: "RESOURCE_VALUE_UNIT", productId: .productID, productName: .productName, productMetric: .productMetric, productCloudpakRatio: .productCloudpakRatio, metricValue: $CALLS|tonumber, aggregationPolicy: "ADD" }' ) RESULT=$(kubectl exec -it $POD -n $NAMESPACE -- curl -k -X POST https://ibm-licensing-service-instance.ibm-common-services.svc.cluster.local:8080/v2/metric_upload?token=$TOKEN -H 'Content-Type: application/json' -d "$PAYLOAD") echo $RESULT
Run the script together with the namespace where your API Connect instance is installed and the number of API calls made:
./my-upload-script.sh <namespace> <your-number-of-api-calls>