public static int appendToLabel(
        final AtomicBuffer metaDataBuffer, final int counterId, final String value)
    {
        Objects.requireNonNull(metaDataBuffer);
        if (counterId < 0)
        {
            throw new IllegalArgumentException("counter id " + counterId + " is negative");
        }

        final int maxCounterId = (metaDataBuffer.capacity() / CountersReader.METADATA_LENGTH) - 1;
        if (counterId > maxCounterId)
        {
            throw new IllegalArgumentException(
                "counter id " + counterId + " out of range: 0 - maxCounterId=" + maxCounterId);
        }

        final int counterMetaDataOffset = CountersReader.metaDataOffset(counterId);
        final int state = metaDataBuffer.getIntVolatile(counterMetaDataOffset);
        if (CountersReader.RECORD_ALLOCATED != state)
        {
            throw new IllegalArgumentException("counter id " + counterId + " is not allocated, state: " + state);
        }

        final int existingLabelLength = metaDataBuffer.getInt(counterMetaDataOffset + CountersReader.LABEL_OFFSET);
        final int remainingLabelLength = CountersReader.MAX_LABEL_LENGTH - existingLabelLength;

        final int writtenLength = metaDataBuffer.putStringWithoutLengthAscii(
            counterMetaDataOffset + CountersReader.LABEL_OFFSET + SIZE_OF_INT + existingLabelLength,
            value,
            0,
            remainingLabelLength);
        if (writtenLength > 0)
        {
            metaDataBuffer.putIntOrdered(
                counterMetaDataOffset + CountersReader.LABEL_OFFSET, existingLabelLength + writtenLength);
        }

        return writtenLength;
    }
@Test
    void appendToLabelShouldAddSuffix()
    {
        final CountersManager countersManager = new CountersManager(
            new UnsafeBuffer(new byte[CountersReader.METADATA_LENGTH]),
            new UnsafeBuffer(ByteBuffer.allocateDirect(CountersReader.COUNTER_LENGTH)),
            StandardCharsets.US_ASCII);
        final int counterId = countersManager.allocate("initial value: ");

        final int length = AeronCounters.appendToLabel(countersManager.metaDataBuffer(), counterId, "test");

        assertEquals(4, length);
        assertEquals("initial value: test", countersManager.getCounterLabel(counterId));
    }