grafana / grafana/alerting

Jira receiver: templates inside JSON-valued custom fields are never rendered

Open
#669 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
89
Forks
74
Avg merge
2d 7h
Merged PRs (30d)
8

Description

**What happens**

Since #416, `receivers/jira/v1` renders Go templates in custom field values. But `config.go` (`NewConfig`, around lines 139 to 143 on `main`) JSON-parses any `fields` value that is valid JSON at configuration load time, and `jira.go` (around lines 146 to 151) renders only values that are still strings, keeping every non-string value as-is. A custom field whose Jira type requires an array or an object can therefore never carry a template.

Example, a Jira Assets field that expects an array of object keys:

```yaml
settings:
fields:
customfield_19509: '[{"key": "{{ .CommonLabels.r1_team_id }}"}]'
```

The value is parsed at load, becomes a non-string, and reaches Jira with the literal `{{ .CommonLabels.r1_team_id }}` as the key. Jira answers `400`, `customfield_19509: Assigned Team is required`. Writing the template as a bare string renders correctly, but Jira then rejects the field because it expects an array. A static value such as `'[{"key": "PTCI-19210975"}]'` works, which confirms the field and the credentials are fine.

**Reproduced**

Grafana 13.1.2 (vendoring grafana/alerting 587c401ed754), through the receiver test API `POST /apis/notifications.alerting.grafana.app/v1beta1/namespaces/default/receivers//test`. `config.go` is unchanged on `main`, and Grafana v13.2.2 vendors e1a167a201a8 with the same code, so every current release behaves this way. The contact point documentation mentions templating for Summary and Labels only and does not state this limitation.

**Why it matters**

Jira Assets fields (team, service, FLA and similar object references) are exactly the fields people want to drive from alert labels, so that one contact point can route a ticket to the owning team. Today the only options are one contact point per team, or a webhook to a service that creates the ticket itself.

**Expected**

Templates inside JSON-valued fields render before the JSON is parsed, or the parsed value is walked and its string leaves are rendered.

**Proposed fix, either shape**

1. In `config.go`, keep the raw string when it contains a template; in `jira.go`, render it and then `json.Unmarshal` the result when it is valid JSON.
2. Or walk parsed values recursively in `jira.go` and render every string leaf.

**Environment**

Grafana 13.1.2 and 13.2.2, Jira Data Center, contact point type `jira`.

Contributor guide

Open the contributing guide

Research direction

Read receivers/jira/v1/config.go around NewConfig and receivers/jira/v1/jira.go around the field-rendering logic, then reproduce the behavior through the receiver test API. Done means a JSON-valued custom field renders template string values before Jira receives the array or object, while static JSON fields continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.