Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add helpers to monitor API parity #388

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

Conversation

mitchnielsen
Copy link
Contributor

@mitchnielsen mitchnielsen commented Feb 26, 2025

Summary

  • Adds a Go script that will identify APIs not implemented in our provider
  • (coming) script to list all APIs
  • (coming) script to list all Terraform resources and datasources

Related to https://linear.app/prefect/issue/PLA-802/automate-the-process-of-checking-api-parity

Testing

$ go run scripts/compare.go
2025/02/26 17:52:30 API 'artifacts' has no Terraform resource equivalent
2025/02/26 17:52:30 API 'collections' has no Terraform resource equivalent
2025/02/26 17:52:30 API 'events' has no Terraform resource equivalent
2025/02/26 17:52:30 API 'slas' has no Terraform resource equivalent

Notes

Here are some scripts I had from my first implementation that outgrew bash a bit:

Click to expand scripts
#!/usr/bin/env bash

resources=$(find internal/provider/resources | grep -v 'test' | awk -F '\/' '{print $4}' | sed 's;\.go;;g')
datasources=$(find internal/provider/datasources | grep -v 'test' | awk -F '\/' '{print $4}' | sed 's;\.go;;g')
unique_resources='automation account_member'

all_resources=( ${resources} ${datasources} ${unique_resources} )

# Print out all the resources.
#
# Sort them and remove the ones that are just the plural equivalent,
# such as "work_pool" and "work_pools".
#
# Also remove provider-specific resources.
printf '%s\n' "${all_resources[@]}" | sort | uniq \
  | grep -v 'base_model' \
  | grep -v 'automation_' \
  | grep -v 'account_members' \
  | grep -v 'teams' \
  | grep -v 'work_pools' \
  | grep -v 'work_queues'
#!/usr/bin/env bash

# Accounts endpoints
account_endpoints=$(curl -s https://api.prefect.cloud/api/openapi.json | jq '.paths | keys' -r | grep '\/api\/accounts\/{account_id}' | grep -v 'workspaces' | sed 's;\/api\/accounts\/{account_id}\/;;g' \
  | awk -F '\/' '{print $1}' \
  | sed 's;\";;g' \
  | sed 's;,;;g' \
  | sed 's;\ ;;g' \
  | sed 's;s$;;g' \
  | sort \
  | uniq)

# Workspace-level endpoints
# ignored: ui/
# ignored: v2/concurrency_limits
workspace_endpoints=$(curl -s https://api.prefect.cloud/api/openapi.json | jq '.paths | keys' -r | grep '\/api\/accounts\/{account_id}' | grep 'workspaces' | sed 's;\/api\/accounts\/{account_id}\/workspaces\/{workspace_id}\/;;g' \
  | grep -v 'v2' \
  | grep -v 'ui' \
  | grep -v 'capabilities' \
  | grep -v 'saved_searches' \
  | grep -v 'bot_access' \
  | grep -v 'access' \
  | grep -v 'team_access' \
  | awk -F '\/' '{print $1}' \
  | sed 's;\";;g' \
  | sed 's;,;;g' \
  | sed 's;\ ;;g' \
  | sed 's;s$;;g' \
  | sort \
  | uniq)

ignored_endpoints='task_run_concurrency_limit global_concurrency_limit block_capabilities saved_searches team_access bot_access access'

all_endpoints=( ${account_endpoints} ${workspace_endpoints} ${ignored_endpoints} )

printf '%s\n' "${all_endpoints[@]}" | sort | uniq
#!/usr/bin/env bash

cleanup() {
  rm -f api-resources.txt provider-resources.txt
}

cleanup

./scripts/api-resources      > api-resources.txt
./scripts/provider-resources > provider-resources.txt

printf 'API resources                                                   Provider resources \n'
printf '==============================================================|============================\n'
diff \
  --color=always \
  --side-by-side \
  --suppress-common-lines \
  --ignore-space-change \
  --ignore-blank-lines \
  --ignore-all-space \
  api-resources.txt provider-resources.txt

cleanup

Requirements

General

  • The contributing guide has been read
  • Title follows the conventional commits format
  • Body includes Closes <issue>, if available
  • Relevant labels have been added
  • Draft status is used until ready for review

Code-level changes

  • Unit tests are added/updated
  • Acceptance tests are added/updated (including import tests, when needed)

New or updated resource/datasource

  • Documentation is added (generated by make docs from source code)
    - When applicable, provide a link back to the relevant page in the Prefect documentation site.
  • For resources, the following are added:
    - Resource example under examples/resources/prefect_<name>/resource.tf
    - Import example under examples/resources/prefect_<name>/import.sh
  • For datasources, the following is added:
    - Datasource example under examples/data-sources,resources>/prefect_<name>/data-source.tf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Maintenance work - won't show in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant