Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Create initial exporter #2

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft

Create initial exporter #2

wants to merge 10 commits into from

Conversation

bendrucker
Copy link
Contributor

Creates the initial version of the exporter

https://takescoop.atlassian.net/browse/PLATFORM-2413

@bendrucker
Copy link
Contributor Author

At the moment, this is a simplified program that fetches agent pools once and exports the metrics to stdout.

Example output from a local run:

[
	{
		"Name": "agents{service.name=unknown_service:terraform-cloud-metrics-exporter,telemetry.sdk.language=go,telemetry.sdk.name=opentelemetry,telemetry.sdk.version=1.7.0,instrumentation.name=terraform_cloud,pool=default,status=idle}",
		"Last": 2,
		"Timestamp": "2022-05-12T16:07:56.779199-07:00"
	},
	{
		"Name": "agents{service.name=unknown_service:terraform-cloud-metrics-exporter,telemetry.sdk.language=go,telemetry.sdk.name=opentelemetry,telemetry.sdk.version=1.7.0,instrumentation.name=terraform_cloud,pool=default,status=exited}",
		"Last": 18,
		"Timestamp": "2022-05-12T16:07:56.779202-07:00"
	}
]

A working initial version would have:

With those two things in place as well as some general refactoring/restructuring (e.g. adding CLI flags, splitting into packages) I should be able to move on to deploy. Probably another 1-2 days work here.

@bendrucker
Copy link
Contributor Author

Re permissions needed to fetch this data, I've observed:

  • Owners can manage (modify) agent resources, as documented
  • Organization tokens can list agent pools and agents
  • Other teams cannot grant agent access. By default, a team has no access to agent APIs. I tried granting all available organization access to a test team. I found its team token is able to list the agent pools, but when listing the agents within a pool, the response is an empty list. Guessing "manage workspaces" confers permission to list agent pools, but not the agents themselves.

An org token seems to be our best near term choice. While still fairly privileged to perform write operations, it's certainly less privileged than an owners token:

https://www.terraform.io/cloud-docs/users-teams-organizations/api-tokens

Copy link

@ryanwholey ryanwholey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope you don't mind a few go-specific questions! The logic for counting agents makes sense to me.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
agents.go Outdated Show resolved Hide resolved
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants