Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Compass metricSourceId add to config-as-code or api call

Phill Pafford
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 12, 2025

So I'm trying to figure out the best way to store or get the 

metricSourceId for each metric configured on my component. Some options I've thought of
  • manually add them to the config-as-code file, BTW this would be a useful add if this was automated
  • curl api call to get all configured metrics for a given component 

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\'

 

1 answer

1 accepted

2 votes
Answer accepted
Emile Raffoul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 12, 2025

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?

Phill Pafford
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 13, 2025

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
Emile Raffoul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 13, 2025

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?

Like Steffen Opel _Utoolity_ likes this
Phill Pafford
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2025

thanks @Emile Raffoul that was one of the things, got it working

 

  • fixed url by adding graphql in the route
  • changed auth to basic

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")
Phill Pafford
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2025

@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
}
}
}
}
}
}
}
}

 

Emile Raffoul
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 16, 2025

@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
}
}
}
}
}
}
}
}

 

Like Steffen Opel _Utoolity_ likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events