Skip to content

feat: add Fastly billing plugin#78

Open
LZG3530606141 wants to merge 1 commit into
opencost:mainfrom
LZG3530606141:feat/fastly-plugin
Open

feat: add Fastly billing plugin#78
LZG3530606141 wants to merge 1 commit into
opencost:mainfrom
LZG3530606141:feat/fastly-plugin

Conversation

@LZG3530606141
Copy link
Copy Markdown

Summary

Implements Fastly billing plugin for OpenCost Plugins, as requested in #48.

What

  • New FastlyCostSource plugin that ingests Fastly CDN billing data into OpenCost
  • Follows the OpenCost plugin architecture (hashicorp go-plugin + gRPC)

Features

  • Invoice listing: Fetches invoices via Fastly Billing v3 API with pagination support
  • Invoice details: Retrieves detailed line items for each invoice
  • Rich cost mapping: Maps Fastly line items to FOCUS spec fields including:
    • Product Group, Product Line, Product Name
    • Usage Type, Region, Units, Rate
    • Billed Cost, List Cost, List Unit Price
  • Rate limiting: Respects Fastly API rate limits (1.5 req/s)
  • API Key authentication: Uses Fastly-Key header for authentication

Implementation Details

  • Plugin directory structure follows OpenCost conventions:
    • cmd/main/main.go - Main plugin implementation
    • cmd/main/main_test.go - Unit tests
    • cmd/validator/main/main.go - Config validator
    • config/fastlyconfig.go - Configuration struct
    • fastlyplugin/fastlybilling.go - API response types
  • Config: fastly_api_key (required), fastly_plugin_log_level (optional)
  • CostSource: "CDN", Domain: "fastly"

Testing

Unit tests cover:

  • Fastly API JSON response unmarshalling
  • Invoice and transaction line item parsing
  • API key header verification via httptest mock server

References

Closes #48

Signed-off-by: LZG3530606141 3530606141@qq.com

- Implement FastlyCostSource for ingesting Fastly CDN billing data
- Fetch invoices via Fastly Billing v3 API with pagination support
- Support detailed line items including product group, product line,
  usage type, region, units, and rate
- Include API key authentication and rate limiting
- Add unit tests for JSON unmarshalling and API response parsing
- Add config validator
- Follow OpenCost plugin architecture (hashicorp go-plugin)

References:
- Fastly Billing API: https://www.fastly.com/documentation/reference/api/account/billing/
- Issue: opencost#48

Signed-off-by: LZG3530606141 <3530606141@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fastly Plugin

1 participant