You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: recorder_test.go
    path of file: ./repos/cockroach/pkg/server/status
    
    the code of the file until where you have to start completion: // Copyright 2015 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

package status

import (
	"bytes"
	"context"
	"io"
	"math/rand"
	"os"
	"reflect"
	"sort"
	"strconv"
	"sync"
	"testing"
	"time"

	"github.com/cockroachdb/cockroach/pkg/build"
	"github.com/cockroachdb/cockroach/pkg/multitenant"
	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/server/status/statuspb"
	"github.com/cockroachdb/cock
    
func TestMetricsRecorderLabels(t *testing.T) {
	defer leaktest.AfterTest(t)()
	nodeDesc := roachpb.NodeDescriptor{
		NodeID: roachpb.NodeID(7),
	}
	reg1 := metric.NewRegistry()
	manual := timeutil.NewManualTime(timeutil.Unix(0, 100))
	st := cluster.MakeTestingClusterSettings()
	recorder := NewMetricsRecorder(
		roachpb.SystemTenantID,
		roachpb.NewTenantNameContainer(catconstants.SystemTenantName),
		nil, /* nodeLiveness */
		nil, /* remoteClocks */
		manual,
		st,
	)
	appReg := metric.NewRegistry()
	logReg := metric.NewRegistry()
	sysReg := metric.NewRegistry()
	recorder.AddNode(reg1, appReg, logReg, sysReg, nodeDesc, 50, "foo:26257", "foo:26258", "foo:5432")

	nodeDescTenant := roachpb.NodeDescriptor{
		NodeID: roachpb.NodeID(7),
	}
	regTenant := metric.NewRegistry()
	stTenant := cluster.MakeTestingClusterSettings()
	tenantID, err := roachpb.MakeTenantID(123)
	require.NoError(t, err)

	appNameContainer := roachpb.NewTenantNameContainer("application")
	recorderTenant := NewMetricsRecorder(
		tenantID,
		appNameContainer,
		nil, /* nodeLiveness */
		nil, /* remoteClocks */
		manual,
		stTenant,
	)
	recorderTenant.AddNode(
		regTenant,
		appReg, logReg, sysReg, nodeDescTenant, 50, "foo:26257", "foo:26258", "foo:5432")

	// ========================================
	// Verify that the recorder exports metrics for tenants as text.
	// ========================================

	g := metric.NewGauge(metric.Metadata{Name: "some_metric"})
	reg1.AddMetric(g)
	g.Update(123)

	g2 := metric.NewGauge(metric.Metadata{Name: "some_metric"})
	regTenant.AddMetric(g2)
	g2.Update(456)

	c1 := metric.NewCounter(metric.Metadata{Name: "some_log_metric"})
	logReg.AddMetric(c1)
	c1.Inc(2)

	recorder.AddTenantRegistry(tenantID, regTenant)

	buf := bytes.NewBuffer([]byte{})
	err = recorder.PrintAsText(buf, expfmt.FmtText)
	require.NoError(t, err)

	require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="system"} 123`)
	require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="application"} 456`)

	bufTenant := bytes.NewBuffer([]byte{})
	err = recorderTenant.PrintAsText(bufTenant, expfmt.FmtText)
	require.NoError(t, err)

	require.NotContains(t, bufTenant.String(), `some_metric{node_id="7",tenant="system"} 123`)
	require.Contains(t, bufTenant.String(), `some_metric{node_id="7",tenant="application"} 456`)

	// Update app name in container and ensure
	// output changes accordingly.
	appNameContainer.Set("application2")

	buf = bytes.NewBuffer([]byte{})
	err = recorder.PrintAsText(buf, expfmt.FmtText)
	require.NoError(t, err)

	require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="system"} 123`)
	require.Contains(t, buf.String(), `some_metric{node_id="7",tenant="application2"} 456`)

	bufTenant = bytes.NewBuffer([]byte{})
	err = recorderTenant.PrintAsText(bufTenant, expfmt.FmtText)
	require.NoError(t, err)

	require.NotContains(t, bufTenant.String(), `some_metric{node_id="7",tenant="system"} 123`)
	require.Contains(t, bufTenant.String(), `some_metric{node_id="7",tenant="application2"} 456`)

	// ========================================
	// Verify that the recorder processes tenant time series registries
	// ========================================

	expectedData := []tspb.TimeSeriesData{
		// System tenant metrics
		{
			Name:   "cr.node.node-id",
			Source: "7",
			Datapoints: []tspb.TimeSeriesDatapoint{
				{
					TimestampNanos: manual.Now().UnixNano(),
					Value:          float64(7),
				},
			},
		},
		{
			Name:   "cr.node.some_metric",
			Source: "7",
			Datapoints: []tspb.TimeSeriesDatapoint{
				{
					TimestampNanos: manual.Now().UnixNano(),
					Value:          float64(123),
				},
			},
		},
		{
			Name:   "cr.node.some_log_metric",
			Source: "7",
			Datapoints: []tspb.TimeSeriesDatapoint{
				{
					TimestampNanos: manual.Now().UnixNano(),
					Value:          float64(2),
				},
			},
		},
		// App tenant metrics
		{
			Name:   "cr.node.node-id",
			Source: "7-123",
			Datapoints: []tspb.TimeSeriesDatapoint{
				{
					TimestampNanos: manual.Now().UnixNano(),
					Value:          float64(nodeDesc.NodeID),
				},
			},
		},
		{
			Name:   "cr.node.some_metric",
			Source: "7-123",
			Datapoints: []tspb.TimeSeriesDatapoint{
				{
					TimestampNanos: manual.Now().UnixNano(),
					Value:          float64(456),
				},
			},
		},
	}

	actualData := recorder.GetTimeSeriesData()

	// compare actual vs expected values
	sort.Sort(byTimeAndName(actualData))
	sort.Sort(byTimeAndName(expectedData))
	if a, e := actualData, expectedData; !reflect.DeepEqual(a, e) {
		t.Errorf("recorder did not yield expected time series collection; diff:\n %v", pretty.Diff(e, a))
	}
}