go.temporal.io/server/common/metrics/registry.go

75 LOC · 23 covered · 52 uncovered · 6 ranges · 23629 concepts · 5 introducers · 11564 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the filego.temporal.io/server/api/metrics/v1/message.pb.go · 128 LOCv1/message.pb.gogo.temporal.io/server/common/build/build.go · 56 LOCbuild/build.gogo.temporal.io/server/common/metrics/defs.go · 76 LOCmetrics/defs.gogo.temporal.io/server/common/metrics/defs_base.go · 30 LOCmetrics/defs_base.gogo.temporal.io/server/common/metrics/noop_impl.go · 58 LOCmetrics/noop_impl.gogo.temporal.io/server/common/metrics/option.go · 21 LOCmetrics/option.gogo.temporal.io/server/common/metrics/otel_options.go · 54 LOCmetrics/otel_options.goTestEmitWorkflowCompletionStats_WorkflowDuration · 0 introduced LOCTestEmitWorkflowCompleti…rate_burst.go ×1 · 2 introduced LOCrate_burst.go ×1shared_structure.go ×3 · 9 introduced LOCshared_structure.go ×3TestAPIs · 0 introduced LOCTestAPIsdeepcopy.go ×2 · 3 introduced LOCdeepcopy.go ×2deepcopy.go ×2 · 7 introduced LOCdeepcopy.go ×2deepcopy.go ×1 · 6 introduced LOCdeepcopy.go ×1deepcopy.go ×1 · 4 introduced LOCdeepcopy.go ×1deepcopy.go ×1 · 5 introduced LOCdeepcopy.go ×1gradual_change.go ×1 · 5 introduced LOCgradual_change.go ×1setting_gen.go ×51 · 335 introduced LOCsetting_gen.go ×51util.go ×1 · 2 introduced LOCutil.go ×1util.go ×5 · 32 introduced LOCutil.go ×5errors.go ×1 · 4 introduced LOCerrors.go ×1util.go ×2 · 6 introduced LOCutil.go ×2util.go ×1 · 3 introduced LOCutil.go ×1util.go ×1 · 5 introduced LOCutil.go ×1util.go ×1 · 5 introduced LOCutil.go ×1metricstest.go ×1 · 3 introduced LOCmetricstest.go ×1counter · 0 introduced LOCcounterconfig.go ×2 · 9 introduced LOCconfig.go ×2otel_metrics_handler.go ×5 · 11 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×3 · 10 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×1 · 2 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×1 · 2 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×2 · 5 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×4 · 15 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×1 · 4 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×1 · 4 introduced LOCotel_metrics_handler.go …otel_metrics_handler.go ×1 · 2 introduced LOCotel_metrics_handler.go …zap_logger.go ×3 · 17 introduced LOCzap_logger.go ×3otel_options.go ×6 · 16 introduced LOCotel_options.go ×6otel_metrics_handler.go ×3 · 16 introduced LOCotel_metrics_handler.go …otel_options.go ×3 · 3 introduced LOCotel_options.go ×3otel_options.go ×1 · 2 introduced LOCotel_options.go ×1registry.go ×1 · 5 introduced LOCregistry.go ×1registry.go ×1 · 1 introduced LOCregistry.go ×1config.go ×2 · 4 introduced LOCconfig.go ×2otel_options.go ×1 · 7 introduced LOCotel_options.go ×1registry.go ×2 · 8 introduced LOCregistry.go ×2tally_metrics_handler.go ×2 · 18 introduced LOCtally_metrics_handler.go…metrics.go ×1 · 1 introduced LOCmetrics.go ×1metrics.go ×1 · 1 introduced LOCmetrics.go ×1metrics.go ×1 · 1 introduced LOCmetrics.go ×1metrics.go ×1 · 1 introduced LOCmetrics.go ×1defs.go ×5 · 91 introduced LOCdefs.go ×5TestCreateHistoryStartWorkflowRequestPayloads · introduced test · go.temporal.io/server/common/TestCreateHistoryStartWorkflowRequestPayloadsTestCreateHistoryStartWo…TestIsContextCanceledErr · introduced test · go.temporal.io/server/common/TestIsContextCanceledErrTestIsContextCanceledErrTestIsContextDeadlineExceededErr · introduced test · go.temporal.io/server/common/TestIsContextDeadlineExceededErrTestIsContextDeadlineExc…TestVerifyShardIDMapping_1VS4 · introduced test · go.temporal.io/server/common/TestVerifyShardIDMapping_1VS4TestVerifyShardIDMapping…TestTSCBWithDynamicSettings · introduced test · go.temporal.io/server/common/circuitbreaker/TestTSCBWithDynamicSettingsTestTSCBWithDynamicSetti…TestDeepCopy_IntSlice · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_IntSliceTestDeepCopy_IntSliceTestDeepCopy_Map · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_MapTestDeepCopy_MapTestDeepCopy_MapMap · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_MapMapTestDeepCopy_MapMapTestDeepCopy_OtherReferenceTypes_Nil · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_OtherReferenceTypes_NilTestDeepCopy_OtherRefere…TestDeepCopy_OtherReferenceTypes_NonNil · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_OtherReferenceTypes_NonNilTestDeepCopy_OtherRefere…TestDeepCopy_Pointer · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_PointerTestDeepCopy_PointerTestDeepCopy_SimpleStruct · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_SimpleStructTestDeepCopy_SimpleStruc…TestDeepCopy_StringSlice · introduced test · go.temporal.io/server/common/dynamicconfig/TestDeepCopy_StringSliceTestDeepCopy_StringSliceTestGradualChangeWhen_ConsistentForSameKey · introduced test · go.temporal.io/server/common/dynamicconfig/TestGradualChangeWhen_ConsistentForSameKeyTestGradualChangeWhen_Co…TestGradualChangeWhen_DifferentKeysHaveDifferentTimes · introduced test · go.temporal.io/server/common/dynamicconfig/TestGradualChangeWhen_DifferentKeysHaveDifferentTimesTestGradualChangeWhen_Di…TestHasSharedStructure · introduced test · go.temporal.io/server/common/dynamicconfig/TestHasSharedStructureTestHasSharedStructureTestStaticGradualChange_WhenReturnsZeroOrPast · introduced test · go.temporal.io/server/common/dynamicconfig/TestStaticGradualChange_WhenReturnsZeroOrPastTestStaticGradualChange_…empty_metric_definition · introduced test · go.temporal.io/server/common/metrics/TestAddOptions/empty_metric_definitionempty_metric_definitionmissing_metric · introduced test · go.temporal.io/server/common/metrics/TestAddOptions/missing_metricmissing_metricopts_overwritten · introduced test · go.temporal.io/server/common/metrics/TestAddOptions/opts_overwrittenopts_overwrittenTestMutexMapBaggage · introduced test · go.temporal.io/server/common/metrics/TestBaggageBenchSuite/TestMutexMapBaggageTestMutexMapBaggageTestSyncMapBaggage · introduced test · go.temporal.io/server/common/metrics/TestBaggageBenchSuite/TestSyncMapBaggageTestSyncMapBaggageTestMeter_TimerInSeconds · introduced test · go.temporal.io/server/common/metrics/TestMeter_TimerInSecondsTestMeter_TimerInSecondsopentelemetry · introduced test · go.temporal.io/server/common/metrics/TestMetricsHandlerFromConfig/opentelemetryopentelemetryTestOtelMetricsHandler_Error · introduced test · go.temporal.io/server/common/metrics/TestOtelMetricsHandler_ErrorTestOtelMetricsHandler_E…TestRegistryBuildCatalog_ErrMetricAlreadyExists · introduced test · go.temporal.io/server/common/metrics/TestRegistryBuildCatalog_ErrMetricAlreadyExistsTestRegistryBuildCatalog…TestRegistryBuildCatalog_Ok · introduced test · go.temporal.io/server/common/metrics/TestRegistryBuildCatalog_OkTestRegistryBuildCatalog…different_keys · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/different_keysdifferent_keysdifferent_ordering · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/different_orderingdifferent_orderingdifferent_values · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/different_valuesdifferent_valuesidentical_multi_tags · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/identical_multi_tagsidentical_multi_tagsidentical_single_tags · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/identical_single_tagsidentical_single_tagskey_boundary_ambiguity · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/key_boundary_ambiguitykey_boundary_ambiguitysingle_vs_multi · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey/single_vs_multisingle_vs_multiTestTagsCacheKey_NoCollisionsForEmbeddedNulls · introduced test · go.temporal.io/server/common/metrics/TestTagsCacheKey_NoCollisionsForEmbeddedNullsTestTagsCacheKey_NoColli…counter · introduced test · go.temporal.io/server/common/metrics/metricstest/TestHandler/countercountergauge · introduced test · go.temporal.io/server/common/metrics/metricstest/TestHandler/gaugegaugeTestExecutionAPIPrioritiesOrdered · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestExecutionAPIPrioritiesOrderedTestExecutionAPIPrioriti…TestExecutionAPIToPriorityMapping · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestExecutionAPIToPriorityMappingTestExecutionAPIToPriori…TestNamespaceReplicationInducingAPIPrioritiesOrdered · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestNamespaceReplicationInducingAPIPrioritiesOrderedTestNamespaceReplication…TestNamespaceReplicationInducingAPIToPriorityMapping · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestNamespaceReplicationInducingAPIToPriorityMappingTestNamespaceReplication…TestNamespaceReplicationInducingAPIs · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestNamespaceReplicationInducingAPIsTestNamespaceReplication…TestVisibilityAPIPrioritiesOrdered · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestVisibilityAPIPrioritiesOrderedTestVisibilityAPIPriorit…TestVisibilityAPIToPriorityMapping · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestVisibilityAPIToPriorityMappingTestVisibilityAPIToPrior…TestVisibilityAPIs · introduced test · go.temporal.io/server/service/frontend/configs/TestQuotasSuite/TestVisibilityAPIsTestVisibilityAPIsTestEmitWorkflowCompletionStats_WorkflowDuration · introduced test · go.temporal.io/server/service/history/workflow/TestEmitWorkflowCompletionStats_WorkflowDurationTestEmitWorkflowCompleti…formatted_message · introduced test · go.temporal.io/server/service/history/workflow/matcher/TestNewMatcherError/formatted_messageformatted_messagemultiple_format_specifiers · introduced test · go.temporal.io/server/service/history/workflow/matcher/TestNewMatcherError/multiple_format_specifiersmultiple_format_specifie…no_format_specifiers · introduced test · go.temporal.io/server/service/history/workflow/matcher/TestNewMatcherError/no_format_specifiersno_format_specifierssimple_message · introduced test · go.temporal.io/server/service/history/workflow/matcher/TestNewMatcherError/simple_messagesimple_messageTestAPIPrioritiesOrdered · introduced test · go.temporal.io/server/service/matching/configs/TestQuotasSuite/TestAPIPrioritiesOrderedTestAPIPrioritiesOrderedTestAPIToPriorityMapping · introduced test · go.temporal.io/server/service/matching/configs/TestQuotasSuite/TestAPIToPriorityMappingTestAPIToPriorityMappingTestAPIs · introduced test · go.temporal.io/server/service/matching/configs/TestQuotasSuite/TestAPIsTestAPIsFocused file · go.temporal.io/server/common/metrics/registry.go · 75 LOCmetrics/registry.go

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 package metrics
2
3 import (
4 "errors"
5 "fmt"
6 "sync"
7 )
8
9 type (
10 // registry tracks a list of metricDefinition objects added with register and then builds a catalog
11 // of them using the buildCatalog method. See globalRegistry for more.
12 registry struct {
13 sync.Mutex
14 definitions []metricDefinition
15 }
16 // catalog is a map of metric name to definition. It should not be modified after it is built.
17 catalog map[string]metricDefinition
18 )
19
20 var (
21 // globalRegistry tracks metrics defined via the New*Def methods. We use a global variable here so that clients may
22 // continue to refer to package-level metrics like metrics.ServiceRequests, while still allowing us to iterate over
23 // all metrics defined in the package to register them with the metrics system. The sequence through which metrics
24 // are registered, sampled and scraped is as follows:
25 //
26 // 1. When the metrics package is initialized, statements calling New*Def are executed to define metrics,
27 // which adds them metric to the global registry.
28 // 2. Before a Handler object is constructed, one this package's fx provider functions will call registry.buildCatalog to
29 // buildCatalog the catalog for these metrics.
30 // 3. The constructed catalog is passed to the Handler so that it knows the metadata for all defined metrics.
31 // 4. Clients call methods on the Handler to obtain metric objects like Handler.Counter and Handler.Timer.
32 // 5. Those methods retrieve the metadata from the catalog and use it to construct the metric object using a
33 // third-party metrics library, e.g. OpenTelemetry. This is where most of the work happens.
34 // 6. Clients record a metric using that metrics object, e.g. by calling CounterFunc, and the sample is recorded.
35 // 7. At some point, the /metrics endpoint is scraped, and the Prometheus handler we register will iterate over all
36 // the aggregated samples and metrics and write them to the response. The metric metadata we passed to the
37 // third-party metrics library in step 5 is used here and rendered in the response as comments like:
38 // # HELP <metric name> <metric description>.
39 globalRegistry registry
40 // errMetricAlreadyExists is returned by registry.buildCatalog when it finds two metrics with the same name.
41 errMetricAlreadyExists = errors.New("metric already exists")
42 )
43
44 // register adds a metric definition to the list of pending metric definitions. This method is thread-safe.
45 > func (c *registry) register(d metricDefinition) { defs.go ×5
46 > c.Lock()
47 > defer c.Unlock()
48 > c.definitions = append(c.definitions, d)
49 > }
50
51 // buildCatalog builds a catalog from the list of pending metric definitions. It is safe to call this method multiple
52 // times. This method is thread-safe.
53 > func (c *registry) buildCatalog() (catalog, error) { registry.go ×2
54 > c.Lock()
55 > defer c.Unlock()
56 >
57 > r := make(catalog, len(c.definitions))
58 > for _, d := range c.definitions {
59 > if original, ok := r[d.name]; ok {
60 > return nil, fmt.Errorf( registry.go ×1
61 > "%w: metric %q already defined with %+v. Cannot redefine with %+v",
62 > errMetricAlreadyExists, d.name, original, d,
63 > )
64 > }
65
66 > r[d.name] = d registry.go ×2
67 }
68
69 > return r, nil registry.go ×1
70 }
71
72 > func (c catalog) getMetric(name string) (metricDefinition, bool) { otel_options.go ×1
73 > def, ok := c[name]
74 > return def, ok
75 > }