Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions docs/services/newrelic.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Parameters

* `apiURL` - the api server url, e.g. https://api.newrelic.com
* `apiKey` - a [NewRelic ApiKey](https://docs.newrelic.com/docs/apis/rest-api-v2/get-started/introduction-new-relic-rest-api-v2/#api_key)
- `apiURL` - the api server url, e.g. https://api.newrelic.com
- `apiKey` - a [NewRelic ApiKey](https://docs.newrelic.com/docs/apis/rest-api-v2/get-started/introduction-new-relic-rest-api-v2/#api_key)

## Configuration

Expand Down Expand Up @@ -43,12 +43,14 @@ metadata:

## Templates

* `description` - __optional__, high-level description of this deployment, visible in the [Summary](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page) page and on the [Deployments](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page) page when you select an individual deployment.
* Defaults to `message`
* `changelog` - __optional__, A summary of what changed in this deployment, visible in the [Deployments](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page) page when you select (selected deployment) > Change log.
* Defaults to `{{(call .repo.GetCommitMetadata .app.status.sync.revision).Message}}`
* `user` - __optional__, A username to associate with the deployment, visible in the [Summary](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page) and on the [Deployments](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page).
* Defaults to `{{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}}`
- `revision` - **optional**, The revision being deployed. Can contain a custom template to extract the revision from your specific application status structure.
- Defaults to `{{.app.status.operationState.syncResult.revision}}`
- `description` - **optional**, high-level description of this deployment, visible in the [Summary](https://docs.newrelic.com/docs/apm/applications-menu/monitoring/apm-overview-page) page and on the [Deployments](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page) page when you select an individual deployment.
- Defaults to `message`
- `changelog` - **optional**, A summary of what changed in this deployment, visible in the [Deployments](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page) page when you select (selected deployment) > Change log.
- Defaults to `{{(call .repo.GetCommitMetadata .app.status.sync.revision).Message}}`
- `user` - **optional**, A username to associate with the deployment, visible in the [Summary](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page) and on the [Deployments](https://docs.newrelic.com/docs/apm/applications-menu/events/deployments-page).
- Defaults to `{{(call .repo.GetCommitMetadata .app.status.sync.revision).Author}}`

```yaml
context: |
Expand Down
5 changes: 5 additions & 0 deletions pkg/services/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ var (
)

func (n *NewrelicNotification) GetTemplater(name string, f texttemplate.FuncMap) (Templater, error) {
revisionTemplate := n.Revision
if revisionTemplate == "" {
revisionTemplate = "{{.app.status.operationState.syncResult.revision}}"
}

revision, err := texttemplate.New(name).Funcs(f).Parse(revisionTemplate)
if err != nil {
return nil, err
Expand Down
116 changes: 81 additions & 35 deletions pkg/services/newrelic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,94 @@ import (
)

func TestGetTemplater_Newrelic(t *testing.T) {
n := Notification{
Newrelic: &NewrelicNotification{
Changelog: "Added: /v2/deployments.rb",
Description: "Deployment finished for {{.app.metadata.name}}. Visit: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
User: "{{.context.user}}",
},
}

templater, err := n.GetTemplater("newrelic", template.FuncMap{})
if !assert.NoError(t, err) {
return
}

var notification Notification

err = templater(&notification, map[string]interface{}{
"context": map[string]interface{}{
"argocdUrl": "https://example.com",
"user": "somebot",
},
"app": map[string]interface{}{
"metadata": map[string]interface{}{
"name": "argocd-notifications",
t.Run("default revision template", func(t *testing.T) {
n := Notification{
Newrelic: &NewrelicNotification{
Changelog: "Added: /v2/deployments.rb",
Description: "Deployment finished for {{.app.metadata.name}}. Visit: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
User: "{{.context.user}}",
},
}

templater, err := n.GetTemplater("newrelic", template.FuncMap{})
if !assert.NoError(t, err) {
return
}

var notification Notification

err = templater(&notification, map[string]interface{}{
"context": map[string]interface{}{
"argocdUrl": "https://example.com",
"user": "somebot",
},
"status": map[string]interface{}{
"operationState": map[string]interface{}{
"syncResult": map[string]interface{}{
"revision": "0123456789",
"app": map[string]interface{}{
"metadata": map[string]interface{}{
"name": "argocd-notifications",
},
"status": map[string]interface{}{
"operationState": map[string]interface{}{
"syncResult": map[string]interface{}{
"revision": "0123456789",
},
},
},
},
},
})

if !assert.NoError(t, err) {
return
}

assert.Equal(t, "0123456789", notification.Newrelic.Revision)
assert.Equal(t, "Added: /v2/deployments.rb", notification.Newrelic.Changelog)
assert.Equal(t, "Deployment finished for argocd-notifications. Visit: https://example.com/applications/argocd-notifications", notification.Newrelic.Description)
assert.Equal(t, "somebot", notification.Newrelic.User)
})

if !assert.NoError(t, err) {
return
}
t.Run("custom revision template", func(t *testing.T) {
n := Notification{
Newrelic: &NewrelicNotification{
Revision: "{{.app.status.custom.revision}}",
Changelog: "Added: /v2/deployments.rb",
Description: "Deployment finished for {{.app.metadata.name}}. Visit: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
User: "{{.context.user}}",
},
}

templater, err := n.GetTemplater("newrelic", template.FuncMap{})
if !assert.NoError(t, err) {
return
}

var notification Notification

err = templater(&notification, map[string]interface{}{
"context": map[string]interface{}{
"argocdUrl": "https://example.com",
"user": "somebot",
},
"app": map[string]interface{}{
"metadata": map[string]interface{}{
"name": "argocd-notifications",
},
"status": map[string]interface{}{
"custom": map[string]interface{}{
"revision": "custom-revision-123",
},
},
},
})

if !assert.NoError(t, err) {
return
}

assert.Equal(t, "0123456789", notification.Newrelic.Revision)
assert.Equal(t, "Added: /v2/deployments.rb", notification.Newrelic.Changelog)
assert.Equal(t, "Deployment finished for argocd-notifications. Visit: https://example.com/applications/argocd-notifications", notification.Newrelic.Description)
assert.Equal(t, "somebot", notification.Newrelic.User)
assert.Equal(t, "custom-revision-123", notification.Newrelic.Revision)
assert.Equal(t, "Added: /v2/deployments.rb", notification.Newrelic.Changelog)
assert.Equal(t, "Deployment finished for argocd-notifications. Visit: https://example.com/applications/argocd-notifications", notification.Newrelic.Description)
assert.Equal(t, "somebot", notification.Newrelic.User)
})
}

func TestSend_Newrelic(t *testing.T) {
Expand Down
Loading