-
-
Notifications
You must be signed in to change notification settings - Fork 805
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
feat(newrelic): Display deploy information from multiple apps #472
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package newrelic | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/wtfutil/wtf/wtf" | ||
nr "github.com/yfronto/newrelic" | ||
) | ||
|
||
func (widget *Widget) display() { | ||
client := widget.currentData() | ||
if client == nil { | ||
widget.Redraw(widget.CommonSettings.Title, " NewRelic data unavailable ", false) | ||
return | ||
} | ||
app, appErr := client.Application() | ||
deploys, depErr := client.Deployments() | ||
|
||
appName := "error" | ||
if appErr == nil { | ||
appName = app.Name | ||
} | ||
|
||
var content string | ||
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, appName) | ||
wrap := false | ||
if depErr != nil { | ||
wrap = true | ||
content = depErr.Error() | ||
} else { | ||
content = widget.contentFrom(deploys) | ||
} | ||
|
||
widget.Redraw(title, content, wrap) | ||
} | ||
|
||
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { | ||
str := fmt.Sprintf( | ||
" %s\n", | ||
"[red]Latest Deploys[white]", | ||
) | ||
|
||
revisions := []string{} | ||
|
||
for _, deploy := range deploys { | ||
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) { | ||
lineColor := "white" | ||
if wtf.IsToday(deploy.Timestamp) { | ||
lineColor = "lightblue" | ||
} | ||
|
||
revLen := 8 | ||
if revLen > len(deploy.Revision) { | ||
revLen = len(deploy.Revision) | ||
} | ||
|
||
str += fmt.Sprintf( | ||
" [green]%s[%s] %s %-.16s[white]\n", | ||
deploy.Revision[0:revLen], | ||
lineColor, | ||
deploy.Timestamp.Format("Jan 02 15:04 MST"), | ||
wtf.NameFromEmail(deploy.User), | ||
) | ||
|
||
revisions = append(revisions, deploy.Revision) | ||
|
||
if len(revisions) == widget.settings.deployCount { | ||
break | ||
} | ||
} | ||
} | ||
|
||
return str | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package newrelic | ||
|
||
import "github.com/gdamore/tcell" | ||
|
||
func (widget *Widget) initializeKeyboardControls() { | ||
widget.SetKeyboardChar("/", widget.ShowHelp, "Show/hide this help window") | ||
widget.SetKeyboardKey(tcell.KeyLeft, widget.PrevSource, "Select previous application") | ||
widget.SetKeyboardKey(tcell.KeyRight, widget.NextSource, "Select next application") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,19 +12,19 @@ const defaultTitle = "NewRelic" | |
type Settings struct { | ||
common *cfg.Common | ||
|
||
apiKey string | ||
applicationID int | ||
deployCount int | ||
apiKey string | ||
deployCount int | ||
applicationIDs []interface{} | ||
} | ||
|
||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings { | ||
|
||
settings := Settings{ | ||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, ymlConfig, globalConfig), | ||
|
||
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_NEW_RELIC_API_KEY")), | ||
applicationID: ymlConfig.UInt("applicationID"), | ||
deployCount: ymlConfig.UInt("deployCount", 5), | ||
apiKey: ymlConfig.UString("apiKey", os.Getenv("WTF_NEW_RELIC_API_KEY")), | ||
deployCount: ymlConfig.UInt("deployCount", 5), | ||
applicationIDs: ymlConfig.UList("applicationIDs"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could keep applicationID for a non-breaking change. Either by appending it to applicationIDs, or doing something like the |
||
} | ||
|
||
return &settings | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,69 @@ | ||
package newrelic | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/rivo/tview" | ||
"github.com/wtfutil/wtf/wtf" | ||
nr "github.com/yfronto/newrelic" | ||
) | ||
|
||
type Widget struct { | ||
wtf.KeyboardWidget | ||
wtf.MultiSourceWidget | ||
wtf.TextWidget | ||
|
||
client *Client | ||
Clients []*Client | ||
|
||
settings *Settings | ||
} | ||
|
||
func NewWidget(app *tview.Application, settings *Settings) *Widget { | ||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget { | ||
widget := Widget{ | ||
TextWidget: wtf.NewTextWidget(app, settings.common, false), | ||
KeyboardWidget: wtf.NewKeyboardWidget(app, pages, settings.common), | ||
MultiSourceWidget: wtf.NewMultiSourceWidget(settings.common, "applicationID", "applicationIDs"), | ||
TextWidget: wtf.NewTextWidget(app, settings.common, true), | ||
|
||
settings: settings, | ||
} | ||
|
||
widget.client = NewClient(widget.settings.apiKey, widget.settings.applicationID) | ||
widget.initializeKeyboardControls() | ||
widget.View.SetInputCapture(widget.InputCapture) | ||
|
||
widget.SetDisplayFunction(widget.display) | ||
|
||
widget.KeyboardWidget.SetView(widget.View) | ||
|
||
return &widget | ||
} | ||
|
||
/* -------------------- Exported Functions -------------------- */ | ||
|
||
func (widget *Widget) Refresh() { | ||
app, appErr := widget.client.Application() | ||
deploys, depErr := widget.client.Deployments() | ||
|
||
appName := "error" | ||
if appErr == nil { | ||
appName = app.Name | ||
for _, id := range wtf.ToInts(widget.settings.applicationIDs) { | ||
widget.Clients = append(widget.Clients, NewClient(widget.settings.apiKey, id)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will create a new client that is calling the service each time, and this is probably not quite what you want. Say you had 3 applications, on the first refresh there would be 3, second would be 6, third would be 9..... eventually this will eat up a lot of resources. |
||
} | ||
|
||
var content string | ||
title := fmt.Sprintf("%s - [green]%s[white]", widget.CommonSettings.Title, appName) | ||
wrap := false | ||
if depErr != nil { | ||
wrap = true | ||
content = depErr.Error() | ||
} else { | ||
content = widget.contentFrom(deploys) | ||
} | ||
sort.Slice(widget.Clients, func(i, j int) bool { | ||
return widget.Clients[i].applicationId < widget.Clients[j].applicationId | ||
}) | ||
|
||
widget.Redraw(title, content, wrap) | ||
widget.display() | ||
} | ||
|
||
func (widget *Widget) HelpText() string { | ||
return widget.KeyboardWidget.HelpText() | ||
} | ||
|
||
/* -------------------- Unexported Functions -------------------- */ | ||
|
||
func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { | ||
str := fmt.Sprintf( | ||
" %s\n", | ||
"[red]Latest Deploys[white]", | ||
) | ||
|
||
revisions := []string{} | ||
|
||
for _, deploy := range deploys { | ||
if (deploy.Revision != "") && wtf.Exclude(revisions, deploy.Revision) { | ||
lineColor := "white" | ||
if wtf.IsToday(deploy.Timestamp) { | ||
lineColor = "lightblue" | ||
} | ||
|
||
revLen := 8 | ||
if revLen > len(deploy.Revision) { | ||
revLen = len(deploy.Revision) | ||
} | ||
|
||
str += fmt.Sprintf( | ||
" [green]%s[%s] %s %-.16s[white]\n", | ||
deploy.Revision[0:revLen], | ||
lineColor, | ||
deploy.Timestamp.Format("Jan 02 15:04 MST"), | ||
wtf.NameFromEmail(deploy.User), | ||
) | ||
|
||
revisions = append(revisions, deploy.Revision) | ||
|
||
if len(revisions) == widget.settings.deployCount { | ||
break | ||
} | ||
} | ||
func (widget *Widget) currentData() *Client { | ||
if len(widget.Clients) == 0 { | ||
return nil | ||
} | ||
|
||
if widget.Idx < 0 || widget.Idx >= len(widget.Clients) { | ||
return nil | ||
} | ||
|
||
return str | ||
return widget.Clients[widget.Idx] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you take a look at the JIRA module and add appropriate keyboard commands?
r/j/k
would be appreciated for consistency.