Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow update to mail error log w/signoff #11156

Merged
merged 9 commits into from
Jun 17, 2024
39 changes: 36 additions & 3 deletions .github/workflows/model-generator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ jobs:
commit_options: "--signoff"
commit_message: "New Models generated"
branch: master

- name: Send Email on Model Generator Failure
if: failure()
uses: dawidd6/action-send-mail@v3.7.1
Expand All @@ -59,7 +58,41 @@ jobs:
body: |
The GitHub Actions workflow in ${{ github.repository }} has failed.
You can find more details in the GitHub Actions log ${{ github.workflow }}.

check-and-email-registry-generate-error:
name: Check and Email Error Log
runs-on: ubuntu-22.04
needs: generate-components
steps:
- name: Download registry-generate-error
uses: actions/download-artifact@v4
with:
name: generate-logs
path: ~/.meshery/logs/registry
- name: Check registry-generate-error file
id: check-registry-generate-error
run: |
if [ -s ~/.meshery/logs/registry/Errors ]; then
echo "registry-generate-error is not empty"
echo "registry-generate-error=true" >> $GITHUB_ENV
else
echo "registry-generate-error is empty"
echo "registry-generate-error=false" >> $GITHUB_ENV
fi
- name: Send Email on Error Logs
if: env.registry-generate-error == 'true'
uses: dawidd6/action-send-mail@v3.7.1
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: Model Generator Error Log
from: |
"Model Generator" <no-reply@meshery.io>
to: developers@meshery.io
body: |
The model generation process encountered errors. Please find the attached error log for details.
attachments: ~/.meshery/logs/registry/Errors
update-components:
name: Update Components
needs: generate-components
Expand Down Expand Up @@ -107,4 +140,4 @@ jobs:
to: developers@meshery.io
body: |
The GitHub Actions workflow in ${{ github.repository }} has failed.
You can find more details in the GitHub Actions log ${{ github.workflow }}.
You can find more details in the GitHub Actions log ${{ github.workflow }}.
38 changes: 23 additions & 15 deletions mesheryctl/internal/cli/root/registry/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
artifactHubRateLimitDur = 5 * time.Minute
artifactHubMutex sync.Mutex
)

var generateCmd = &cobra.Command{
Use: "generate",
Short: "Generate Models",
Expand All @@ -80,11 +79,18 @@
return ErrUpdateRegistry(err, modelLocation)
}
utils.Log.SetLevel(logrus.DebugLevel)
logFilePath := filepath.Join(logDirPath, "registry-generate")
logFilePath := filepath.Join(logDirPath, "Logs")

Check warning on line 82 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L82

Added line #L82 was not covered by tests
logFile, err = os.Create(logFilePath)
if err != nil {
return err
}

utils.LogError.SetLevel(logrus.ErrorLevel)
logErrorFilePath := filepath.Join(logDirPath, "Errors")
errorLogFile, err = os.Create(logErrorFilePath)
if err != nil {
return err

Check warning on line 92 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L88-L92

Added lines #L88 - L92 were not covered by tests
}
return nil
},

Expand All @@ -102,13 +108,13 @@

srv, err = mutils.NewSheetSRV(spreadsheeetCred)
if err != nil {
utils.Log.Error(ErrUpdateRegistry(err, modelLocation))
utils.LogError.Error(ErrUpdateRegistry(err, modelLocation))

Check warning on line 111 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L111

Added line #L111 was not covered by tests
return err
}

resp, err := srv.Spreadsheets.Get(spreadsheeetID).Fields().Do()
if err != nil || resp.HTTPStatusCode != 200 {
utils.Log.Error(ErrUpdateRegistry(err, outputLocation))
utils.LogError.Error(ErrUpdateRegistry(err, outputLocation))

Check warning on line 117 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L117

Added line #L117 was not covered by tests
return err
}

Expand All @@ -120,7 +126,7 @@
err = InvokeGenerationFromSheet(&wg)
if err != nil {
// meshkit
utils.Log.Error(err)
utils.LogError.Error(err)

Check warning on line 129 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L129

Added line #L129 was not covered by tests
return err
}

Expand All @@ -146,11 +152,13 @@
logModelGenerationSummary(modelToCompGenerateTracker)

utils.Log.UpdateLogOutput(os.Stdout)
utils.LogError.UpdateLogOutput(os.Stdout)

Check warning on line 155 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L155

Added line #L155 was not covered by tests
utils.Log.Info(fmt.Sprintf("Summary: %d models, %d components generated.", totalAggregateModel, totalAggregateComponents))

utils.Log.Info("See ", logDirPath, " for detailed logs.")

_ = logFile.Close()
_ = errorLogFile.Close()

Check warning on line 161 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L161

Added line #L161 was not covered by tests
totalAggregateModel = 0
totalAggregateComponents = 0
}()
Expand All @@ -166,7 +174,7 @@
}

utils.Log.UpdateLogOutput(logFile)

utils.LogError.UpdateLogOutput(errorLogFile)

Check warning on line 177 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L177

Added line #L177 was not covered by tests
var wgForSpreadsheetUpdate sync.WaitGroup
wgForSpreadsheetUpdate.Add(1)
go func() {
Expand Down Expand Up @@ -194,14 +202,14 @@
if mutils.ReplaceSpacesAndConvertToLowercase(model.Registrant) == "meshery" {
err = GenerateDefsForCoreRegistrant(model)
if err != nil {
utils.Log.Error(err)
utils.LogError.Error(err)

Check warning on line 205 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L205

Added line #L205 was not covered by tests
}
return
}

generator, err := generators.NewGenerator(model.Registrant, model.SourceURL, model.Model)
if err != nil {
utils.Log.Error(ErrGenerateModel(err, model.Model))
utils.LogError.Error(ErrGenerateModel(err, model.Model))

Check warning on line 212 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L212

Added line #L212 was not covered by tests
return
}

Expand All @@ -211,25 +219,25 @@
}
pkg, err := generator.GetPackage()
if err != nil {
utils.Log.Error(ErrGenerateModel(err, model.Model))
utils.LogError.Error(ErrGenerateModel(err, model.Model))

Check warning on line 222 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L222

Added line #L222 was not covered by tests
return
}

version := pkg.GetVersion()
modelDirPath, compDirPath, err := createVersionedDirectoryForModelAndComp(version, model.Model)
if err != nil {
utils.Log.Error(ErrGenerateModel(err, model.Model))
utils.LogError.Error(ErrGenerateModel(err, model.Model))

Check warning on line 229 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L229

Added line #L229 was not covered by tests
return
}
modelDef, err := writeModelDefToFileSystem(&model, version, modelDirPath)
if err != nil {
utils.Log.Error(err)
utils.LogError.Error(err)

Check warning on line 234 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L234

Added line #L234 was not covered by tests
return
}

comps, err := pkg.GenerateComponents()
if err != nil {
utils.Log.Error(ErrGenerateModel(err, model.Model))
utils.LogError.Error(ErrGenerateModel(err, model.Model))

Check warning on line 240 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L240

Added line #L240 was not covered by tests
return
}
utils.Log.Info("Current model: ", model.Model)
Expand Down Expand Up @@ -290,7 +298,7 @@
path, err := url.Parse(model.SourceURL)
if err != nil {
err = ErrGenerateModel(err, model.Model)
utils.Log.Error(err)
utils.LogError.Error(err)

Check warning on line 301 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L301

Added line #L301 was not covered by tests
return nil
}
gitRepo := github.GitRepo{
Expand All @@ -300,7 +308,7 @@
owner, repo, branch, root, err := gitRepo.ExtractRepoDetailsFromSourceURL()
if err != nil {
err = ErrGenerateModel(err, model.Model)
utils.Log.Error(err)
utils.LogError.Error(err)

Check warning on line 311 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L311

Added line #L311 was not covered by tests
return nil
}

Expand Down Expand Up @@ -337,7 +345,7 @@
err = componentDef.WriteComponentDefinition(compDirPath)
if err != nil {
err = ErrGenerateComponent(err, model.Model, componentDef.DisplayName)
utils.Log.Error(err)
utils.LogError.Error(err)

Check warning on line 348 in mesheryctl/internal/cli/root/registry/generate.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/registry/generate.go#L348

Added line #L348 was not covered by tests
}
return nil
})
Expand Down
3 changes: 2 additions & 1 deletion mesheryctl/internal/cli/root/registry/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import (
var (
modelLocation string
logFile *os.File
errorLogFile *os.File
sheetGID int64
totalAggregateComponents int
logDirPath = filepath.Join(mutils.GetHome(), ".meshery", "logs")
logDirPath = filepath.Join(mutils.GetHome(), ".meshery", "logs", "registry")
)

var updateCmd = &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion mesheryctl/internal/cli/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,6 @@
}

func setupLogger() {
utils.SetupMeshkitLogger(verbose, nil)
utils.Log = utils.SetupMeshkitLogger("mesheryctl", verbose, os.Stdout)
utils.LogError = utils.SetupMeshkitLogger("mesheryctl-error", verbose, os.Stderr)

Check warning on line 204 in mesheryctl/internal/cli/root/root.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/internal/cli/root/root.go#L203-L204

Added lines #L203 - L204 were not covered by tests
}
6 changes: 3 additions & 3 deletions mesheryctl/pkg/utils/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
}

// Initialize Meshkit Logger instance
func SetupMeshkitLogger(debugLevel bool, output io.Writer) {
func SetupMeshkitLogger(name string, debugLevel bool, output io.Writer) logger.Handler {

Check warning on line 28 in mesheryctl/pkg/utils/formatter.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/pkg/utils/formatter.go#L28

Added line #L28 was not covered by tests
logLevel := viper.GetInt("LOG_LEVEL")
if !debugLevel {
logLevel = int(log.DebugLevel)
}

logger, err := logger.New("mesheryctl", logger.Options{
logger, err := logger.New(name, logger.Options{

Check warning on line 34 in mesheryctl/pkg/utils/formatter.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/pkg/utils/formatter.go#L34

Added line #L34 was not covered by tests
Format: logger.TerminalLogFormat,
LogLevel: logLevel,
Output: output,
Expand All @@ -40,5 +40,5 @@
log.Error(err)
os.Exit(1)
}
Log = logger
return logger

Check warning on line 43 in mesheryctl/pkg/utils/formatter.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/pkg/utils/formatter.go#L43

Added line #L43 was not covered by tests
}
2 changes: 2 additions & 0 deletions mesheryctl/pkg/utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ var (
Log logger.Handler
// Color for the whiteboard printer
whiteBoardPrinter = color.New(color.FgHiBlack, color.BgWhite, color.Bold)
//global logger error variable
LogError logger.Handler
)

var CfgFile string
Expand Down
2 changes: 1 addition & 1 deletion mesheryctl/pkg/utils/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
// setup meshkit logger for testing and return the buffer in which commands output is to be set.
func SetupMeshkitLoggerTesting(_ *testing.T, verbose bool) *bytes.Buffer {
b := bytes.NewBufferString("")
SetupMeshkitLogger(verbose, b)
Log = SetupMeshkitLogger("mesheryctl", verbose, b)

Check warning on line 174 in mesheryctl/pkg/utils/testing.go

View check run for this annotation

Codecov / codecov/patch

mesheryctl/pkg/utils/testing.go#L174

Added line #L174 was not covered by tests
return b
}

Expand Down
Loading