# Alert Rules Lost Migrate to 2.4 from 2.39

**URL:** <https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985>\
**Category:** PMM 2.x\
**Created:** [October 17, 2023, 5:03pm UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985 "2023-10-17T17:03:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![meyerder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/meyerder/32/16994_2.png) [@meyerder](https://forums.percona.com/u/meyerder)\
**Post date:** [October 17, 2023, 5:03pm UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985/1 "2023-10-17T17:03:07Z")

</div>

## Description:

After migration all rules are lost with the following message now showing the following

 ![image](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/2X/c/cffbea71957d6ee4323139062db3f5efe8d64fcf.png)

Errors loading rules  
Failed to load Grafana rules state: failure getting rules: invalid character ‘z’ after object key:value pair; failure getting rules: invalid character ‘z’ after object key:value pair  
Failed to load Grafana rules config: failed to get alert rules: invalid character ‘z’ after object key:value pair

## Steps to Reproduce:

Docker upgrade via the gui

## Version:

2.39 to 2.40

## Logs:

[logs.txt](https://forums.percona.com/uploads/short-url/44Z4MRz5cJnt8z1QXFZ0hvOSGUV.txt) (66.5 KB)

Rules Should remain

## Actual Result:

Alert Rules were lost

---

<div class="post-metadata">

**Author:** ![lalit.choudhary](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/lalit.choudhary/32/51_2.png) [@lalit.choudhary](https://forums.percona.com/u/lalit.choudhary)\
**Post date:** [October 18, 2023, 5:21am UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985/2 "2023-10-18T05:21:16Z")

</div>

Hello @meyerder

In this case, you need to create/convert alert templates as the new pmm version changed many things for alerting.  
Here is the reference from pmm doc, [Percona Alerting - Percona Monitoring and Management](https://docs.percona.com/percona-monitoring-and-management/get-started/alerting.html#template-compatibility-with-previous-pmm-versions)

If you are upgrading from PMM 2.25 and earlier, alert templates will not be automatically migrated. This is because PMM 2.26.0 introduced significant changes to the core structure of rule templates.

In this scenario, you will need to manually recreate any custom rule templates that you want to transfer to PMM 2.26.0 or later.

Alert rules created with Integrated Alerting in PMM 2.30 and earlier are not automatically migrated to Percona Alerting.

---

<div class="post-metadata">

**Author:** ![meyerder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/meyerder/32/16994_2.png) [@meyerder](https://forums.percona.com/u/meyerder)\
**Post date:** [October 18, 2023, 1:25pm UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985/3 "2023-10-18T13:25:12Z")

</div>

@lalit.choudhary ALL alert rules are gone… All Alert templates migrated properly… All Alert Rules/templates were built on 2.39 as I have not had this instance up for more than a month or maybe 45 days

If you could give me a clue as to where to look to troubleshoot the issue that would help

I found this… but that is sqllite and not PostgreSQL It makes me think that the issue might be with one of the grafana alerts that may have existed (I cant remember but I may have had one or two grafana managed alerts vs all pmm templates)

> <https://github.com/grafana/grafana/issues/66636>
>
> \<!--
> Please use this template to create your bug report. By providing as much i…nfo as possible you help us understand the issue, reproduce it and resolve it for you quicker. Therefore take a couple of extra minutes to make sure you have provided all info needed.
> 
> PROTIP: record your screen and attach it as a gif to showcase the issue.
> 
> \- Questions should be posted to: https://community.grafana.com
> \- Use query inspector to troubleshoot issues: https://bit.ly/2XNF6YS
> \- How to record and attach gif: https://bit.ly/2Mi8T6K
> \--\>
> 
> \*\*What happened\*\*:
> \*\*Switching from sqlite3 to mysql\*\*, unable to show old alert rules:
> "Failed to load Grafana rules state: failure getting rules: invalid character 'c' after object key:value pair; failure getting rules: invalid character 'c' after object key:value pair
> Failed to load Grafana rules config: failed to get alert rules: invalid character 'c' after object key:value pair"
> 
> \*\*Even when I create \*\*a new alert rule\*\*\*\*, it shows:"Failed to save rule: failed to get group alert rules: invalid character 'c' after object key:value pair"
>       
> \*\*Datasource\*\*: Prometheus
> \*\*Metrics browser\*\*: kube\_pod\_container\_status\_ready{namespace=~"aaa|bbb"}
> \*\*B expression\*\*: 
> Operation Reduce, Function:Last, Input:A, Mode:Strict
> \*\*C expression\*\*
> Operation:Math, Expression: $B \> 0
> \*\*Evaluate every\*\*: 10s for 30s
> \*\*Folder\*\*：“xxx”， GROUP：“COMMON”
> 
> \*\* grafana log \*\*
> logger=context traceID=00000000000000000000000000000000 userId=1 orgId=1 uname=admin t=2023-04-15T22:09:15.061363967+08:00 level=error msg="failed to get alert rules: invalid character 'c' after object key:value pair" error="failed to get alert rules: invalid character 'c' after object key:value pair" remote\_addr=10.249.102.15 traceID=00000000000000000000000000000000
> 
> logger=context traceID=00000000000000000000000000000000 userId=1 orgId=1 uname=admin t=2023-04-15T22:10:08.129559456+08:00 level=error msg="failed to get group alert rules: invalid character 'c' after object key:value pair" error="failed to get group alert rules: invalid character 'c' after object key:value pair" remote\_addr=10.249.102.15 traceID=00000000000000000000000000000000
> logger=context traceID=00000000000000000000000000000000 userId=1 orgId=1 uname=admin t=2023-04-15T22:10:08.129761725+08:00 level=error msg="Request Completed" method=GET path=/api/ruler/grafana/api/v1/rules/运营监控/COMMON status=500 remote\_addr=10.249.102.15 time\_ms=30 duration=30.098243ms size=141 referer="http://10.14.32.240:3000/alerting/new?returnTo=%2Falerting%2Flist" traceID=00000000000000000000000000000000
> logger=ngalert t=2023-04-15T22:10:10.003059703+08:00 level=error msg="scheduler failed to update alert rules" err="failed to get alert rules: invalid character 'c' after object key:value pair"
> 
> \*\*What you expected to happen\*\*:
> can load old alert rules and save alert rule normally.
> 
> \*\*How to reproduce it (as minimally and precisely as possible)\*\*:
> everytime when I create this alert rule.
> 
> \*\*Anything else we need to know?\*\*:
> Migaration from sqllite3 to mysql 5.7.29.
> 
> \*\*Environment\*\*:
> \- Grafana version: v9.1.0
> \- Data source type & version: Prometheus
> \- OS Grafana is installed on: Ubuntu
> \- User OS & Browser: Chorme
> \- Grafana plugins: 
> \- Others: Using mysql(5.7.29) for storing

---

<div class="post-metadata">

**Author:** ![nurlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/nurlan/32/1523_2.png) [@nurlan](https://forums.percona.com/u/nurlan)\
**Post date:** [October 20, 2023, 11:32am UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985/4 "2023-10-20T11:32:22Z")

</div>

@meyerder could you run following commands within docker container and provide result  
`psql -U grafana`  
`select id, data, from alert_rule`

---

<div class="post-metadata">

**Author:** ![meyerder](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/meyerder/32/16994_2.png) [@meyerder](https://forums.percona.com/u/meyerder)\
**Post date:** [October 21, 2023, 11:08pm UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985/5 "2023-10-21T23:08:11Z")

</div>

@nurlan Looks like it was a single alert rule… the data was not in a proper json format it looks like… I deleted this rule and all works…

```auto
[{"refId":"A","queryType":"range","relativeTimeRange":{"from":3600,"to":0},"datasourceUid":"NuQ5hK64k","model":{"datasource":{"type":"loki","uid":"NuQ5hK64k"},"editorMode":"builder","expr":"sum by(applid) (count_over_time({job=\"system_logs\", filename=\"/var/log/messages\", applid=~\"xxx\", hostname=\"xxxxx\"} |~ "xxx" [1h]))","hide":false,"intervalMs":1000,"legendFormat":"{{appid}}","maxDataPoints":43200,"queryType":"range","refId":"A"}},{"refId":"B","queryType":"","relativeTimeRange":{"from":3600,"to":0},"datasourceUid":" __expr__","model":{"conditions":[{"evaluator":{"params":[14],"type":"lt"},"operator":{"type":"and"},"query":{"params":["A"]},"reducer":{"params":[],"type":"avg"},"type":"query"}],"datasource":{"type":" __expr__","uid":" __expr__"},"expression":"A","hide":false,"intervalMs":1000,"maxDataPoints":43200,"refId":"B","type":"classic_conditions"}}]

```

---

<div class="post-metadata">

**Author:** ![nurlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/nurlan/32/1523_2.png) [@nurlan](https://forums.percona.com/u/nurlan)\
**Post date:** [October 23, 2023, 6:20am UTC](https://forums.percona.com/t/alert-rules-lost-migrate-to-2-4-from-2-39/25985/6 "2023-10-23T06:20:26Z")

</div>

Great, thanks for update
