**Build scan:**
https://gradle-enterprise.elastic.co/s/6vcr6fptcfcym/tests/:x-pack:plugin:transform:test/org.elasticsearch.xpack.transform.transforms.TransformHealthCheckerTests/testPersistenceFailure

**Reproduction line:**
`gradlew ':x-pack:plugin:transform:test' --tests "org.elasticsearch.xpack.transform.transforms.TransformHealthCheckerTests.testPersistenceFailure" -Dtests.seed=AC00B6A09D5C731 -Dtests.locale=en-US -Dtests.timezone=America/Jamaica -Druntime.java=19`

**Applicable branches:**
main

**Reproduces locally?:**
No

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.xpack.transform.transforms.TransformHealthCheckerTests&tests.test=testPersistenceFailure

**Failure excerpt:**
```
java.lang.AssertionError: 
Expected: a value equal to or greater than <2022-10-25T08:38:19.009993300Z>
     but: <2022-10-25T08:38:19.009Z> was less than <2022-10-25T08:38:19.009993300Z>

  at __randomizedtesting.SeedInfo.seed([AC00B6A09D5C731:50563472D7BB29A0]:0)
  at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:18)
  at org.junit.Assert.assertThat(Assert.java:956)
  at org.junit.Assert.assertThat(Assert.java:923)
  at org.elasticsearch.xpack.transform.transforms.TransformHealthCheckerTests.testPersistenceFailure(TransformHealthCheckerTests.java:49)
  at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
  at java.lang.reflect.Method.invoke(Method.java:578)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1758)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$8.evaluate(RandomizedRunner.java:946)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$9.evaluate(RandomizedRunner.java:982)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$10.evaluate(RandomizedRunner.java:996)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleSetupTeardownChained$1.evaluate(TestRuleSetupTeardownChained.java:44)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at org.apache.lucene.tests.util.TestRuleThreadAndTestName$1.evaluate(TestRuleThreadAndTestName.java:45)
  at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
  at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.forkTimeoutingTask(ThreadLeakControl.java:843)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$3.evaluate(ThreadLeakControl.java:490)
  at com.carrotsearch.randomizedtesting.RandomizedRunner.runSingleTest(RandomizedRunner.java:955)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$5.evaluate(RandomizedRunner.java:840)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$6.evaluate(RandomizedRunner.java:891)
  at com.carrotsearch.randomizedtesting.RandomizedRunner$7.evaluate(RandomizedRunner.java:902)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleStoreClassName$1.evaluate(TestRuleStoreClassName.java:38)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.NoShadowingOrOverridesOnMethodsRule$1.evaluate(NoShadowingOrOverridesOnMethodsRule.java:40)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at org.apache.lucene.tests.util.TestRuleAssertionsRequired$1.evaluate(TestRuleAssertionsRequired.java:53)
  at org.apache.lucene.tests.util.AbstractBeforeAfterRule$1.evaluate(AbstractBeforeAfterRule.java:43)
  at org.apache.lucene.tests.util.TestRuleMarkFailure$1.evaluate(TestRuleMarkFailure.java:44)
  at org.apache.lucene.tests.util.TestRuleIgnoreAfterMaxFailures$1.evaluate(TestRuleIgnoreAfterMaxFailures.java:60)
  at org.apache.lucene.tests.util.TestRuleIgnoreTestSuites$1.evaluate(TestRuleIgnoreTestSuites.java:47)
  at com.carrotsearch.randomizedtesting.rules.StatementAdapter.evaluate(StatementAdapter.java:36)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl$StatementRunner.run(ThreadLeakControl.java:390)
  at com.carrotsearch.randomizedtesting.ThreadLeakControl.lambda$forkTimeoutingTask$0(ThreadLeakControl.java:850)
  at java.lang.Thread.run(Thread.java:1589)

```
x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/transforms/TransformHealthCheckerTests.java
assertEquals(1, health.getIssues().size());
        assertThat(health.getIssues().get(0).getIssue(), equalTo("Task encountered failures updating internal state"));
        assertThat(health.getIssues().get(0).getFirstOccurrence(), greaterThanOrEqualTo(now));
        assertThat(health.getIssues().get(0).getFirstOccurrence(), lessThan(Instant.MAX));
        context.resetStatePersistenceFailureCount();
        assertThat(TransformHealthChecker.checkTransform(task), equalTo(TransformHealth.GREEN));
    }
    public void testStatusSwitchingAndMultipleFailures() {
        TransformTask task = mock(TransformTask.class);
        TransformContext context = createTestContext();
        Instant now = getNow();
        withIdStateAndContext(task, randomAlphaOfLength(10), context);
        assertThat(TransformHealthChecker.checkTransform(task), equalTo(TransformHealth.GREEN));
        context.incrementAndGetFailureCount(new ElasticsearchException("internal error"));
        TransformHealth health = TransformHealthChecker.checkTransform(task);
        assertThat(health.getStatus(), equalTo(HealthStatus.YELLOW));
        Instant firstOccurrence = health.getIssues().get(0).getFirstOccurrence();
        assertThat(firstOccurrence, greaterThanOrEqualTo(now));
        assertThat(firstOccurrence, lessThan(Instant.MAX));
        for (int i = 1; i < TransformHealthChecker.RED_STATUS_FAILURE_COUNT_BOUNDARY; ++i) {
            context.incrementAndGetFailureCount(new ElasticsearchException("internal error"));
            assertThat(TransformHealthChecker.checkTransform(task).getStatus(), equalTo(HealthStatus.YELLOW));
            assertEquals(1, TransformHealthChecker.checkTransform(task).getIssues().size());
            assertThat(health.getIssues().get(0).getFirstOccurrence(), equalTo(firstOccurrence));
        }
        
        context.incrementAndGetFailureCount(new ElasticsearchException("internal error"));
        assertThat(TransformHealthChecker.checkTransform(task).getStatus(), equalTo(HealthStatus.RED));
        assertEquals(1, TransformHealthChecker.checkTransform(task).getIssues().size());
        assertThat(health.getIssues().get(0).getFirstOccurrence(), equalTo(firstOccurrence));