Skip to content

Commit

Permalink
Use Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro committed Feb 8, 2024
1 parent 319aeb2 commit c2af7a9
Show file tree
Hide file tree
Showing 67 changed files with 262 additions and 4,315 deletions.
1 change: 1 addition & 0 deletions collector-framework/pkg/collectors/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ func RegisterCollector(collectorName string, builderFunc collectonBuilderFunc, i
optional: make([]string, 0),
}
}
fmt.Print(collectorName)
registry.register(collectorName, builderFunc, inclusionType)
}
2 changes: 1 addition & 1 deletion collector-framework/pkg/loglines/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (lt *GenerationalLockedTime) Generation() uint32 {
func (lt *GenerationalLockedTime) Update(update time.Time) {
lt.lock.Lock()
defer lt.lock.Unlock()
if update.Sub(lt.time) > 0 {
if update.After(lt.time) {
lt.time = update
lt.generation += 1
}
Expand Down
13 changes: 5 additions & 8 deletions collector-framework/pkg/runner/collector_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ package runner
import (
"strings"

log "github.com/sirupsen/logrus"

"github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework/pkg/collectors"
log "github.com/sirupsen/logrus"
)

var (
Expand All @@ -16,12 +15,6 @@ var (
All string = "all"
)

func init() {
registry := collectors.GetRegistry()
OptionalCollectorNames = registry.GetOptionalNames()
RequiredCollectorNames = registry.GetRequiredNames()
}

func isIn(name string, arr []string) bool {
for _, arrVal := range arr {
if name == arrVal {
Expand All @@ -45,6 +38,10 @@ func removeDuplicates(arr []string) []string {
// collectors to be run it will enfore that required colletors
// are returned
func GetCollectorsToRun(selectedCollectors []string) []string {
registry := collectors.GetRegistry()
OptionalCollectorNames = registry.GetOptionalNames()
RequiredCollectorNames = registry.GetRequiredNames()

collectorNames := make([]string, 0)
collectorNames = append(collectorNames, RequiredCollectorNames...)
for _, name := range selectedCollectors {
Expand Down
18 changes: 9 additions & 9 deletions tgm-collector/doc/implementing_a_collector.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sequenceDiagram
note left of callback: Callback.Call()
callback ->> User: Presents formatted data to user
Collector ->>- Runner: Sends poll sucess/failure via results channel
note left of Collector: resultsChan <- PollResult{CollectorName, Errors}
note left of Collector: resultsChan <- collectorsBase.PollResult{CollectorName, Errors}
Runner ->> Runner: Reacts to failures
end
Expand Down Expand Up @@ -75,7 +75,7 @@ package collectors
import (
"fmt"

"github.com/redhat-partner-solutions/vse-sync-collection-tools/tgm-collector/pkg/callbacks"
"github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework/pkg/callbacks"
)
const (
AnnouncementCollectorName = "MyCustomerAnouncer"
Expand All @@ -99,31 +99,31 @@ func (annMsg *AnnouncementMessage) GetAnalyserFormat() (*callbacks.AnalyserFor

// Collector
type AnnouncementCollector struct {
*baseCollector
*collectorsBase.ExecCollector
msg string
}

func (announcer *AnnouncementCollector) Poll(resultsChan chan PollResult, wg *utils.WaitGroupCount) {
func (announcer *AnnouncementCollector) Poll(resultsChan chan collectorsBase.PollResult, wg *utils.WaitGroupCount) {
defer func() {
wg.Done()
}()

msg := &AnnouncementMessage{Msg: announcer.msg}

errs := make([]error, 0)
err := announcer.callback.Call(&msg, AnnouncementMsg)
err := announcer.Callback.Call(&msg, AnnouncementMsg)
if err != nil {
errs = append(errs, fmt.Errorf("callback failed %w", err))
}
resultsChan <- PollResult{
resultsChan <- collectorsBase.PollResult{
CollectorName: AnnouncementCollectorName,
Errors: errorsToReturn,
}
}

func NewAnnouncementCollector(constuctor *CollectionConstuctor) (Collector, error) {
func NewAnnouncementCollector(constuctor *CollectionConstuctor) (collectorsBase.Collector, error) {
announcer := AnnouncementCollector{
baseCollector: newBaseCollector(
ExecCollector: collectorsBase.NewExecCollector(
constructor.PollInterval,
false,
constructor.Callback,
Expand All @@ -135,6 +135,6 @@ func NewAnnouncementCollector(constuctor *CollectionConstuctor) (Collector, erro

func init(){
// We'll make this a required collector
RegisterCollector(AnnouncementCollectorName, NewAnnouncementCollector, required)
collectorsBase.RegisterCollector(AnnouncementCollectorName, NewAnnouncementCollector, required)
}
```
7 changes: 5 additions & 2 deletions tgm-collector/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ require (
github.com/icza/backscanner v0.0.0-20230330133933-bf6beb754c70
github.com/onsi/ginkgo/v2 v2.9.0
github.com/onsi/gomega v1.27.1
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084
github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework v0.0.0-00010101000000-000000000000
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.0
golang.org/x/mod v0.8.0
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
k8s.io/kubectl v0.26.1
)

replace github.com/redhat-partner-solutions/vse-sync-collection-tools/collector-framework => ../collector-framework

require (
github.com/creack/pty v1.1.17 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -44,6 +45,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/openshift/api v0.0.0-20230120195050-6ba31fa438f2 // indirect
github.com/openshift/client-go v0.0.0-20230120202327-72f107311084 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -61,6 +63,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.0 // indirect
k8s.io/kube-openapi v0.0.0-20230217203603-ff9a8e8fa21d // indirect
k8s.io/kubectl v0.26.1 // indirect
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
134 changes: 0 additions & 134 deletions tgm-collector/pkg/callbacks/callbacks.go

This file was deleted.

89 changes: 0 additions & 89 deletions tgm-collector/pkg/callbacks/callbacks_test.go

This file was deleted.

Loading

0 comments on commit c2af7a9

Please sign in to comment.