Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions tfutils/plan_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@ import (
k8sAdapters "github.com/overmindtech/k8s-source/adapters"
"github.com/overmindtech/sdp-go"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"

"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)

type MapStatus int

func (m MapStatus) String() string {
switch m {
case MapStatusSuccess:
return "success"
case MapStatusNotEnoughInfo:
return "not enough info"
case MapStatusUnsupported:
return "unsupported"
default:
return "unknown"
}
}

const (
MapStatusSuccess MapStatus = iota
MapStatusNotEnoughInfo
Expand Down Expand Up @@ -117,6 +133,10 @@ type TfMapData struct {
// number of supported and unsupported changes and returns the mapped item
// differences.
func MappedItemDiffsFromPlan(ctx context.Context, planJson []byte, fileName string, lf log.Fields) (*PlanMappingResult, error) {
// Create a span for this since we're going to be attaching events to it when things fail to map
span := trace.SpanFromContext(ctx)
defer span.End()

// Check that we haven't been passed a state file
if isStateFile(planJson) {
return nil, fmt.Errorf("'%v' appears to be a state file, not a plan file", fileName)
Expand Down Expand Up @@ -215,6 +235,20 @@ func MappedItemDiffsFromPlan(ctx context.Context, planJson []byte, fileName stri
results.Results = append(results.Results, mapResourceToQuery(itemDiff, currentResource, relevantMappings))
}

// Attach failed mappings to the span
for _, result := range results.Results {
switch result.Status {
case MapStatusUnsupported, MapStatusNotEnoughInfo:
span.AddEvent("UnmappedResource", trace.WithAttributes(
attribute.String("ovm.climap.status", result.Status.String()),
attribute.String("ovm.climap.message", result.Message),
attribute.String("ovm.climap.terraform-name", result.TerraformName),
))
case MapStatusSuccess:
// Don't include these
}
}

return &results, nil
}

Expand Down
Loading