Instana

Instana

The community for performance and observability professionals to learn, to share ideas, and to connect with others.

 View Only

How to use the offset in API in analyze entities?

  • 1.  How to use the offset in API in analyze entities?

    Posted Wed July 31, 2024 05:46 AM

    Our Instana team got this question a couple weeks ago and I forgot to share my answer with the community, basically the use case was:

    How can I get more records if Instana has a maximum retrievalSize of 200?

    Run the first query with the retrievalSize desired, in my case I used 20 (or without the retrievalSize to get the 200 records)
    curl -XPOST --url https://your-tenant.instana.io/api/infrastructure-monitoring/analyze/entities -H "Content-Type: application/json" -H "authorization: apiToken $apiToken" -d '{"timeFrame":{"to":1721024167443,"windowSize":3600000},"tagFilterExpression":{"type":"EXPRESSION","logicalOperator":"AND","elements":[]},"pagination":{"retrievalSize":20},"type":"host","metrics":[{"metric":"cpu.used","aggregation":"MEAN","label":"CPU Used"},{"metric":"memory.used","aggregation":"MEAN","label":"Memory Used"}],"order":{"by":"label","direction":"ASC"}}'
    In your results, you get the cursor (object (InfraExploreCursor) named next:
    "canLoadMore":true,"totalHits":48,"totalRepresentedItemCount":48,"totalRetainedItemCount":48,"next":{"@class":"com.instana.ui.model.explore.InfraExploreCursor","totalHits":48,"totalRepresentedItemCount":48,"ingestionTime":1721023500000,"offset":20},"adjustedTimeframe":null}
    As you can see, you can load more results, I have a total of 48 hits and the offset is 20... so, copy-paste that @class to your next query:
    curl -XPOST --url https://your-tenant.instana.io/api/infrastructure-monitoring/analyze/entities -H "Content-Type: application/json" -H "authorization: apiToken $apiToken" -d '{"timeFrame":{"to":1721024167443,"windowSize":3600000},"tagFilterExpression":{"type":"EXPRESSION","logicalOperator":"AND","elements":[]},"pagination":{"cursor":{"@class":"com.instana.ui.model.explore.InfraExploreCursor","totalHits":48,"totalRepresentedItemCount":48,"ingestionTime":1721023500000,"offset":20}, "retrievalSize":20},"type":"host","metrics":[{"metric":"cpu.used","aggregation":"MEAN","label":"CPU Used"},{"metric":"memory.used","aggregation":"MEAN","label":"Memory Used"}],"order":{"by":"label","direction":"ASC"}}'
    I got this in the results:
    "canLoadMore":true,"totalHits":48,"totalRepresentedItemCount":48,"totalRetainedItemCount":48,"next":{"@class":"com.instana.ui.model.explore.InfraExploreCursor","totalHits":48,"totalRepresentedItemCount":48,"ingestionTime":1721023500000,"offset":40},"adjustedTimeframe":null}
    Nice, I can load more, then I ran this, just changed the offset to 40:
    curl -XPOST --url https://your-tenant.instana.io/api/infrastructure-monitoring/analyze/entities -H "Content-Type: application/json" -H "authorization: apiToken $apiToken" -d '{"timeFrame":{"to":1721024167443,"windowSize":3600000},"tagFilterExpression":{"type":"EXPRESSION","logicalOperator":"AND","elements":[]},"pagination":{"cursor":{"@class":"com.instana.ui.model.explore.InfraExploreCursor","totalHits":48,"totalRepresentedItemCount":48,"ingestionTime":1721023500000,"offset":40}, "retrievalSize":20},"type":"host","metrics":[{"metric":"cpu.used","aggregation":"MEAN","label":"CPU Used"},{"metric":"memory.used","aggregation":"MEAN","label":"Memory Used"}],"order":{"by":"label","direction":"ASC"}}'
    This is the last result:
    "canLoadMore":false,"totalHits":48,"totalRepresentedItemCount":48,"totalRetainedItemCount":48,"next":null,"adjustedTimeframe":null}
    And that's it, I can't load more and my next is null , I got all the results paginated.

    Hope this helps anyone out there.



    ------------------------------
    Israel Ochoa
    CSM Architect - Instana NCEE Market
    IBM
    Stockholm
    ------------------------------