gcp

package
v0.0.0-...-a836525 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package gcp contains the GCP Billing Export → FOCUS converter implementation.

Provider-specific converters live in subpackages. During migration, this package may be empty in default builds until the implementation is moved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyUnifiedPostMapGCP

func ApplyUnifiedPostMapGCP(fr *types.FocusRecord, obj map[string]interface{})

ApplyUnifiedPostMapGCP finalizes a FocusRecord using fields from a JSON object map. Mirrors root behavior; exported so root shims can delegate here.

func EnrichUnified

func EnrichUnified(fr *types.FocusRecord, raw map[string]interface{})

EnrichUnified fills in derived fields the minimal mapping rules omit so unified output matches legacy semantics. Mirrors the former root enrichGCPUnified behavior without changing semantics or metrics.

func EnsureUsageUnit

func EnsureUsageUnit(fr *types.FocusRecord, obj map[string]interface{})

EnsureUsageUnit sets UsageUnit based on raw row hints or PricingUnit when empty.

func GetMappingRules

func GetMappingRules() *types.MappingRules

GetMappingRules returns GCP field mapping rules for the unified mapper.

func OpenInput

func OpenInput(inputPath string) (io.ReadCloser, string, error)

OpenInput opens the input file (CSV or JSON), handles gzip transparently, and returns a ReadCloser along with the detected inner extension (".csv" or ".json").

func ProcessCSV

func ProcessCSV(
	ctx context.Context,
	reader io.Reader,
	config *types.ConversionConfig,
	dw types.DataWriter,
	progress *types.ConversionProgress,
	start time.Time,
	cb types.ProgressCallback,
	pathLabel string,
	mapper func(headers []string, rows [][]string) ([]types.FocusRecord, int),
) (int64, int64, int64, error)

ProcessCSV streams GCP CSV records in chunks, maps them via the provided mapper, writes them using the given DataWriter, and reports progress. It mirrors the legacy root implementation semantics (classifier metrics are emitted by the mapper).

Parameters: - reader: CSV source (already decompressed if needed) - config: conversion configuration - dw: data writer for output - progress: progress struct to mutate - start: conversion start time - cb: optional progress callback - pathLabel: telemetry label ("legacy" or "unified") for mapper latency metric - mapper: function(headers, chunk) -> (mappedRecords, errorsCount)

func ProcessJSON

func ProcessJSON(
	ctx context.Context,
	reader io.Reader,
	config *types.ConversionConfig,
	dw types.DataWriter,
	mapObjectToFocus func(obj map[string]interface{}) *types.FocusRecord,
) (int64, int64, int64, error)

ProcessJSON streams GCP JSON data. It supports both array-of-objects and NDJSON forms. Mapping of classifier metrics should be handled by the provided mapObjectToFocus function to preserve legacy behavior. Returns (recordCount, processedRecords, errorRecords, error).

Types

type FullJSONMapper

type FullJSONMapper struct{}

FullJSONMapper maps a JSON object (map[string]any) to a FocusRecord fields-only. Caller is responsible for classification and metrics to preserve root behavior.

func NewFullJSONMapper

func NewFullJSONMapper() *FullJSONMapper

func (*FullJSONMapper) Map

func (m *FullJSONMapper) Map(obj map[string]interface{}) (*types.FocusRecord, bool, bool)

Map returns (FocusRecord pointer, hasCredits, isSpot)

type FullRowMapper

type FullRowMapper struct {
	// contains filtered or unexported fields
}

FullRowMapper maps a CSV row to a FocusRecord using header name lookup. It performs pure field extraction/enrichment and credit parsing but leaves final charge classification to the caller to avoid import cycles.

func NewFullRowMapper

func NewFullRowMapper(headers []string) *FullRowMapper

func (*FullRowMapper) Map

func (m *FullRowMapper) Map(row []string) (types.FocusRecord, bool, bool, error)

Map converts a row to FocusRecord and returns flags (hasCredits, spotCredit). Classification is intentionally not done here.

type GCPConverter

type GCPConverter struct {
	// contains filtered or unexported fields
}

GCPConverter implements GCP Billing export to FOCUS conversion. Mirrors the legacy behavior while living in the provider package to preserve public APIs.

func NewGCPConverter

func NewGCPConverter() *GCPConverter

NewGCPConverter creates a new provider-scoped converter.

func (*GCPConverter) Convert

Convert delegates to ConvertStream (streaming default kept for parity).

func (*GCPConverter) ConvertStream

func (g *GCPConverter) ConvertStream(ctx context.Context, config *types.ConversionConfig, progressCallback types.ProgressCallback) (*types.ConversionResult, error)

ConvertStream performs streaming conversion from CSV/JSON inputs.

func (*GCPConverter) EstimateConversion

func (g *GCPConverter) EstimateConversion(_ context.Context, config *types.ConversionConfig) (*types.ConversionEstimate, error)

EstimateConversion provides simple estimates by file size.

func (*GCPConverter) GetSchema

func (g *GCPConverter) GetSchema() *types.FocusSchema

GetSchema returns FOCUS schema

func (*GCPConverter) GetSupportedFormats

func (g *GCPConverter) GetSupportedFormats() *types.SupportedFormats

GetSupportedFormats returns supported formats for GCP

func (*GCPConverter) ProcessChunk

func (g *GCPConverter) ProcessChunk(_ context.Context, _ []byte, _ int) ([]types.FocusRecord, error)

ProcessChunk is not used; required by interface.

func (*GCPConverter) ValidateInput

func (g *GCPConverter) ValidateInput(_ context.Context, config *types.ConversionConfig) error

ValidateInput validates input existence and basic format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL