Adopting beats/v7 v7.8.1 - custom beat no longer compiles, refactoring help needed

I have several custom beats that I am now refactoring to adopt the beats/v7 and go modules.
The trivial main.go no longer compile as there are breaking changes and the new API replacement is unclear how to use it.

The change is the RootCmd variable no longer exists:
See: https://github.com/elastic/beats/pull/15853
See: https://github.com/elastic/beats/blob/master/filebeat/cmd/root.go

Here is my original code ( filebeat variant that includes my custom regexprocessor:

    package main 
     
    import (
                     "github.com/elastic/beats/filebeat/cmd"
                     _ "githubdev.dco.elmae/CloudPlatform/em-top-beats/maventbeat/regexprocessor"
                    "log"
                    "os"
    )
  
    func main() {
     
                     if err := cmd.RootCmd.Execute(); err != nil {
                                     log.Printf("Error: %v\n", err)
                                     os.Exit(1)
                     }
     }

There is a public API that takes abeater.PluginFactory parameter that I’m unsure how to set it so as to maintain compatibility.
I tried passing nil and it compiles and runs but it does not process events correctly.

rootCmd := cmd.GenRootCmdWithSettings(beater.New(nil), instance.Settings{Name: "filebeat"})

func Filebeat(inputs beater.PluginFactory) *cmd.BeatsRootCmd {

What is the recipe for refactoring my code, specifically passing in beater.PluginFactory ?

Is your Beat based on Filebeat? Or is it a custom generated Beat?

HI. It is a customized filebeat so I can add a custom regexprocessor.
One day, I may add a PR to get regexprocessor contributed to beats.
I found the solution was to do like the code for filebeat main.go

Thanks for helping get beats using go modules.
I was able to ditch all the vendor folders after refactoring.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.