Skip to content

Commit

Permalink
flowmode: only report usagestats for builtin components (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfratto authored Mar 22, 2024
1 parent df75c28 commit adda065
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
27 changes: 27 additions & 0 deletions internal/component/component_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package component
import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -73,13 +74,39 @@ func (id ID) String() string {
return id.ModuleID + "/" + id.LocalID
}

// Type denotes a type of component.
type Type int

const (
// TypeInvalid is an invalid value for Type.
TypeInvalid Type = iota
TypeBuiltin // TypeBuiltin represents builtin components.
TypeCustom // TypeCustom represents custom components defined using `declare`.
)

// String returns a string representation of the component type.
func (t Type) String() string {
switch t {
case TypeInvalid:
return "<invalid>"
case TypeBuiltin:
return "builtin"
case TypeCustom:
return "custom"
default:
return fmt.Sprintf("Type(%d)", t)
}
}

// Info ia detailed information about a component.
type Info struct {
// Component is the instance of the component. Component may be nil if a
// component exists in the controller's DAG but it has not been successfully
// evaluated yet.
Component Component

Type Type // Type of the component.

// ModuleIDs includes the list of current module IDs that the component is
// running. Module IDs are always globally unique.
//
Expand Down
9 changes: 9 additions & 0 deletions internal/flow/flow_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (f *Flow) getComponentDetail(cn controller.ComponentNode, graph *dag.Graph,
LocalID: cn.NodeID(),
},
Label: cn.Label(),
Type: componentType(cn),

References: references,
ReferencedBy: referencedBy,
Expand All @@ -129,3 +130,11 @@ func (f *Flow) getComponentDetail(cn controller.ComponentNode, graph *dag.Graph,
}
return componentInfo
}

func componentType(cn controller.ComponentNode) component.Type {
if _, ok := cn.(*controller.BuiltinComponentNode); ok {
return component.TypeBuiltin
}

return component.TypeCustom
}
3 changes: 3 additions & 0 deletions internal/flowmode/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@ func getEnabledComponentsFunc(f *flow.Flow) func() map[string]interface{} {
components := component.GetAllComponents(f, component.InfoOptions{})
componentNames := map[string]struct{}{}
for _, c := range components {
if c.Type != component.TypeBuiltin {
continue
}
componentNames[c.ComponentName] = struct{}{}
}
return map[string]interface{}{"enabled-components": maps.Keys(componentNames)}
Expand Down

0 comments on commit adda065

Please sign in to comment.