So I'm trying to figure out the best way to store or get the
I'm running datacenter and everything needs to be done manually, so just trying to think about the best way to implement, since there is little support for datacenter and compass integration
If I could choose, please make it an API call so I can get a current list of all metrics configured
example api request:
curl --request GET \
--url https://acme.atlassian.net/gateway/api/compass/v1/metrics/${component_id} \
--user "$USER_EMAIL:$USER_API_KEY" \
--header "Accept: application/json" \
--header "Content-Type: application/json"
example config-as-code:
name: my-api
id: 'ari:cloud:compass:12j3hg123jhg123hj:component/34io5u34oi5u3oi4u534/324klj34kjl4jl3k4j'
metrics:
- name: build time
metricId: 'ari:cloud:compass:12j3hg123jhg123hjg123:metric-source/34io5u34oi5u3oi4u534/kwpoerkekmfemcpeck23\'
Hi @Phill Pafford ,
Thanks for reaching out!
There is currently a GraphQL API where you can provide a component ID and request all the metricSources for that component.
The full API reference can be found here but here's an example GraphQL request body also:
query getComponentDetails($id: ID!) {
compass {
component(id: $id) {
... on CompassComponent {
metricSources {
...on CompassComponentMetricSourcesConnection {
nodes {
id
}
}
}
}
}
}
}
And providing the input variables:
{
"id": "yourComponentId"
}
In this query I'm only returning the metricSource IDs but you can add extra fields to the query such as the metricDefinition and name also.
Would this work for your use case?
while that works, my script is not for some reason
any ideas?
#!/usr/bin/env bash
set -e
# Configuration
ATLASSIAN_URL="https://acme.atlassian.net/gateway/api"
ATLASSIAN_TOKEN="lkasjdlkajsdlkjaslkdjalksjdlkajsdlkajsdlkajsdlkajskldjalkdjlaksjdlkasjdkjasdlkajsdlkasjdklajdlksajdkalsjd"
CONTENT_TYPE="application/json"
GRAPHQL_QUERY=$(cat <<EOF
query getComponentDetails(\$id: ID!) {
compass {
component(id: \$id) {
... on CompassComponent {
metricSources {
... on CompassComponentMetricSourcesConnection {
nodes {
id
}
}
}
}
}
}
}
EOF
)
# Parameters for the query
COMPASS_COMPONENT_ID="ari:cloud:compass:sdlkfjslkdjflksjdlkfjsdlkfjslkdjflksdjf-sdlfslkdfjlsdkjflksdjflksdjflsdjfsd-d234234234"
# Construct the variables JSON
VARIABLES_JSON=$(cat <<EOF
{
"id": "$COMPASS_COMPONENT_ID"
}
EOF
)
REQUEST_JSON=$(cat <<EOF
{
"query": "$GRAPHQL_QUERY",
"variables": $VARIABLES_JSON
}
EOF
)
## format as JSON
REQUEST_JSON=$(echo $REQUEST_JSON | jq -c)
# Make the GraphQL request using curl
response=$(curl -v -X -L POST \
-H "Authorization: Bearer $ATLASSIAN_TOKEN" \
-H "Content-Type: $CONTENT_TYPE" \
-d "$REQUEST_JSON" \
"$ATLASSIAN_URL")
echo "$response"
exit 0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Phill Pafford ,
There's a couple of possible fixes to try:
1. update the ATLASSIAN_URL to include "/graphql" at the end. In full, it would be:
https://<your_site>/gateway/api/graphql
2. try a different auth header. Here's some details for generating and using Atlassian API tokens: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/
If the above doesn't help, can you provide more details regarding any errors you are receiving?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks @Emile Raffoul that was one of the things, got it working
example:
ATLASSIAN_BASIC_AUTH=$(echo -n $ATLASSIAN_USER:$ATLASSIAN_TOKEN | base64)
response=$(curl -v -X POST \
-H "Authorization: Basic $ATLASSIAN_BASIC_AUTH" \
-H "Content-Type: $CONTENT_TYPE" \
-d "$REQUEST_JSON" \
"$ATLASSIAN_URL")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Emile Raffoul also trying to add the name of each metric as well, basically I want to pull all metrics configured for a component, then push data for the ones configured, but need to know what each metric is so I can push the correct value, I have added metricDefinition id but would you change anything in the query?
query getComponentDetails($id: ID!) {
compass {
component(id: $id) {
...on CompassComponent {
metricSources {
...on CompassComponentMetricSourcesConnection {
nodes {
id
, metricDefinition {
id
}
}
}
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Phill Pafford I'm glad to hear that fixed it!
Yes you are correct to add metricDefinition like that to get the the underlying metric's details.
If you'd like `name`, you can add that along side the `id`. e.g:
query getComponentDetails($id: ID!) {
compass {
component(id: $id) {
... on CompassComponent {
metricSources {
...on CompassComponentMetricSourcesConnection {
nodes {
id
metricDefinition {
id
name
}
}
}
}
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.