Looks like bad synchronization or some other data race in the new metrics framework:

```
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 23 out of bounds for length 22	
	at java.util.ArrayList.add(ArrayList.java:484) ~[?:?]	
	at java.util.ArrayList.add(ArrayList.java:496) ~[?:?]	
	at org.elasticsearch.telemetry.MetricRecorder$RegisteredMetric.call(MetricRecorder.java:52) ~[framework-8.12.0-SNAPSHOT.jar:8.12.0-SNAPSHOT]	
	at org.elasticsearch.telemetry.MetricRecorder.call(MetricRecorder.java:87) ~[framework-8.12.0-SNAPSHOT.jar:8.12.0-SNAPSHOT]	
	at org.elasticsearch.telemetry.MetricRecorder.call(MetricRecorder.java:80) ~[framework-8.12.0-SNAPSHOT.jar:8.12.0-SNAPSHOT]	
	at org.elasticsearch.telemetry.RecordingInstruments$RecordingInstrument.call(RecordingInstruments.java:45) ~[framework-8.12.0-SNAPSHOT.jar:8.12.0-SNAPSHOT]	
	at org.elasticsearch.telemetry.RecordingInstruments$RecordingLongCounter.incrementBy(RecordingInstruments.java:167) ~[framework-8.12.0-SNAPSHOT.jar:8.12.0-SNAPSHOT]	
	at org.elasticsearch.repositories.s3.S3BlobStore$IgnoreNoResponseMetricsCollector.collectMetrics(S3BlobStore.java:174) ~[main/:?]
```

**Build scan:**
https://gradle-enterprise.elastic.co/s/skb2qbd7ok7q4/tests/:modules:repository-s3:internalClusterTest/org.elasticsearch.repositories.s3.S3BlobStoreRepositoryTests/testSnapshotAndRestore
**Reproduction line:**
```
./gradlew ':modules:repository-s3:internalClusterTest' --tests "org.elasticsearch.repositories.s3.S3BlobStoreRepositoryTests.testSnapshotAndRestore" -Dtests.seed=E3086D1C08A70A29 -Dtests.locale=en-CA -Dtests.timezone=Africa/Gaborone -Druntime.java=21
```

**Applicable branches:**
main

**Reproduces locally?:**
Didn't try

**Failure history:**
https://gradle-enterprise.elastic.co/scans/tests?tests.container=org.elasticsearch.repositories.s3.S3BlobStoreRepositoryTests&tests.test=testSnapshotAndRestore


**Failure excerpt:**
```
org.elasticsearch.snapshots.SnapshotException: [tfpcle:dub/vL7GHIFCQsSWZQQypgpGjg] failed to update snapshot in repository

  at org.elasticsearch.repositories.blobstore.BlobStoreRepository.lambda$finalizeSnapshot$21(BlobStoreRepository.java:1719)
  at org.elasticsearch.action.ActionListenerImplementations$DelegatingResponseActionListener.acceptException(ActionListenerImplementations.java:186)
  at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
  at org.elasticsearch.action.ActionListenerImplementations$DelegatingResponseActionListener.onFailure(ActionListenerImplementations.java:191)
  at org.elasticsearch.action.support.SubscribableListener$FailureResult.complete(SubscribableListener.java:322)
  at org.elasticsearch.action.support.SubscribableListener.tryComplete(SubscribableListener.java:234)
  at org.elasticsearch.action.support.SubscribableListener.setResult(SubscribableListener.java:259)
  at org.elasticsearch.action.support.SubscribableListener.onFailure(SubscribableListener.java:178)
  at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
  at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
  at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
  at org.elasticsearch.action.support.SubscribableListener$FailureResult.complete(SubscribableListener.java:322)
  at org.elasticsearch.action.support.SubscribableListener.tryComplete(SubscribableListener.java:234)
  at org.elasticsearch.action.support.SubscribableListener.setResult(SubscribableListener.java:259)
  at org.elasticsearch.action.support.SubscribableListener.onFailure(SubscribableListener.java:178)
  at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
  at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
  at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
  at org.elasticsearch.action.support.SubscribableListener$FailureResult.complete(SubscribableListener.java:322)
  at org.elasticsearch.action.support.SubscribableListener.tryComplete(SubscribableListener.java:234)
  at org.elasticsearch.action.support.SubscribableListener.setResult(SubscribableListener.java:259)
  at org.elasticsearch.action.support.SubscribableListener.onFailure(SubscribableListener.java:178)
  at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
  at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
  at org.elasticsearch.action.DelegatingActionListener.onFailure(DelegatingActionListener.java:27)
  at org.elasticsearch.action.ActionListenerImplementations.safeAcceptException(ActionListenerImplementations.java:62)
  at org.elasticsearch.action.ActionListenerImplementations.safeOnFailure(ActionListenerImplementations.java:73)
  at org.elasticsearch.action.ActionListener$4.onFailure(ActionListener.java:336)
  at org.elasticsearch.action.support.RefCountingListener.finish(RefCountingListener.java:127)
  at org.elasticsearch.core.AbstractRefCounted$1.closeInternal(AbstractRefCounted.java:117)
  at org.elasticsearch.core.AbstractRefCounted.decRef(AbstractRefCounted.java:69)
  at org.elasticsearch.action.support.RefCountingRunnable.close(RefCountingRunnable.java:116)
  at org.elasticsearch.core.Releasables$3.close(Releasables.java:142)
  at org.elasticsearch.action.support.RefCountingListener$1.onResponse(RefCountingListener.java:151)
  at org.elasticsearch.action.support.RefCountingListener$1.onResponse(RefCountingListener.java:146)
  at org.elasticsearch.action.ActionRunnable$1.doRun(ActionRunnable.java:36)
  at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
  at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
  at java.lang.Thread.run(Thread.java:1583)

  Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 23 out of bounds for length 22

    at java.util.ArrayList.add(ArrayList.java:484)
    at java.util.ArrayList.add(ArrayList.java:496)
    at org.elasticsearch.telemetry.MetricRecorder$RegisteredMetric.call(MetricRecorder.java:52)
    at org.elasticsearch.telemetry.MetricRecorder.call(MetricRecorder.java:87)
    at org.elasticsearch.telemetry.MetricRecorder.call(MetricRecorder.java:80)
    at org.elasticsearch.telemetry.RecordingInstruments$RecordingInstrument.call(RecordingInstruments.java:45)
    at org.elasticsearch.telemetry.RecordingInstruments$RecordingLongCounter.incrementBy(RecordingInstruments.java:167)
    at org.elasticsearch.repositories.s3.S3BlobStore$IgnoreNoResponseMetricsCollector.collectMetrics(S3BlobStore.java:174)
    at org.elasticsearch.repositories.s3.S3BlobStore$1.collectMetrics(S3BlobStore.java:130)
    at com.amazonaws.AmazonWebServiceClient.endClientExecution(AmazonWebServiceClient.java:819)
    at com.amazonaws.AmazonWebServiceClient.endClientExecution(AmazonWebServiceClient.java:799)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5480)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:5403)
    at com.amazonaws.services.s3.AmazonS3Client.access$300(AmazonS3Client.java:421)
    at com.amazonaws.services.s3.AmazonS3Client$PutObjectStrategy.invokeServiceCall(AmazonS3Client.java:6531)
    at com.amazonaws.services.s3.AmazonS3Client.uploadObject(AmazonS3Client.java:1861)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1821)
    at org.elasticsearch.repositories.s3.S3BlobContainer.lambda$executeSingleUpload$16(S3BlobContainer.java:435)
    at org.elasticsearch.repositories.s3.SocketAccess.lambda$doPrivilegedVoid$0(SocketAccess.java:46)
    at java.security.AccessController.doPrivileged(AccessController.java:319)
    at org.elasticsearch.repositories.s3.SocketAccess.doPrivilegedVoid(SocketAccess.java:45)
    at org.elasticsearch.repositories.s3.S3BlobContainer.executeSingleUpload(S3BlobContainer.java:435)
    at org.elasticsearch.repositories.s3.S3BlobContainer.lambda$writeBlob$1(S3BlobContainer.java:135)
    at java.security.AccessController.doPrivileged(AccessController.java:571)
    at org.elasticsearch.repositories.s3.SocketAccess.doPrivilegedIOException(SocketAccess.java:37)
    at org.elasticsearch.repositories.s3.S3BlobContainer.writeBlob(S3BlobContainer.java:133)
    at org.elasticsearch.common.blobstore.BlobContainer.writeBlob(BlobContainer.java:119)
    at org.elasticsearch.repositories.s3.S3BlobContainer$1.onCompletion(S3BlobContainer.java:199)
    at org.elasticsearch.repositories.blobstore.ChunkedBlobOutputStream.close(ChunkedBlobOutputStream.java:95)
    at org.elasticsearch.repositories.s3.S3BlobContainer.writeMetadataBlob(S3BlobContainer.java:223)
    at org.elasticsearch.repositories.blobstore.ChecksumBlobStoreFormat.write(ChecksumBlobStoreFormat.java:347)
    at org.elasticsearch.repositories.blobstore.ChecksumBlobStoreFormat.write(ChecksumBlobStoreFormat.java:330)
    at org.elasticsearch.repositories.blobstore.BlobStoreRepository.lambda$finalizeSnapshot$14(BlobStoreRepository.java:1630)
    at org.elasticsearch.action.ActionRunnable$1.doRun(ActionRunnable.java:35)
    at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:983)
    at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:26)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.lang.Thread.run(Thread.java:1583)

```
test/framework/src/main/java/org/elasticsearch/telemetry/MetricRecorder.java
called.computeIfAbsent(Objects.requireNonNull(name), k -> new ArrayList<>()).add(call);
        }
    }
    /**
     * The containers for each metric type.
     */
    private final Map<InstrumentType, RegisteredMetric<I>> metrics;
    public MetricRecorder() {
        metrics = new HashMap<>(InstrumentType.values().length);
        for (var instrument : InstrumentType.values()) {
            metrics.put(instrument, new RegisteredMetric<>(new HashMap<>(), new HashMap<>(), new HashMap<>(), new ArrayList<>()));
        }
    }
    /**
     * Register an instrument.  Instruments must be registered before they are used.
     */
    public void register(I instrument, InstrumentType instrumentType, String name, String description, String unit) {
        metrics.get(instrumentType).register(name, description, unit, instrument);
    }
    /**
     * Record a call made to a registered Elasticsearch {@link Instrument}.
     */
    public void call(Instrument instrument, Number value, Map<String, Object> attributes) {
        call(InstrumentType.fromInstrument(instrument), instrument.getName(), value, attributes);
    }
    /**
     * Record a call made to the registered instrument represented by the {@link InstrumentType} enum.
     */
    public void call(InstrumentType instrumentType, String name, Number value, Map<String, Object> attributes) {
        metrics.get(instrumentType).call(name, new Measurement(value, attributes, instrumentType.isDouble));