(t *testing.T)
| 840 | } |
| 841 | |
| 842 | func TestNegotiatePrometheusTextVersion(t *testing.T) { |
| 843 | const prometheusAccept = "application/openmetrics-text;version=1.0.0;escaping=allow-utf-8;q=0.6,application/openmetrics-text;version=0.0.1;q=0.5,text/plain;version=1.0.0;escaping=allow-utf-8;q=0.4,text/plain;version=0.0.4;q=0.3,*/*;q=0.2" |
| 844 | type testCase struct { |
| 845 | name string |
| 846 | accept string |
| 847 | accepted []Format |
| 848 | want Format |
| 849 | sample string |
| 850 | } |
| 851 | tests := []testCase{ |
| 852 | { |
| 853 | name: "Prometheus scrape preserves UTF-8 without OpenMetrics", |
| 854 | accept: prometheusAccept, |
| 855 | accepted: DefaultAcceptedFormats(), |
| 856 | want: FmtText_1_0_0.WithEscapingScheme(model.NoEscaping), |
| 857 | sample: `{"my.metric","my.label"="v"} 1`, |
| 858 | }, |
| 859 | { |
| 860 | name: "explicit UTF-8 text 1.0.0 with OpenMetrics enabled", |
| 861 | accept: "text/plain;version=1.0.0;escaping=allow-utf-8", |
| 862 | accepted: DefaultOpenMetricsAcceptedFormats(), |
| 863 | want: FmtText_1_0_0.WithEscapingScheme(model.NoEscaping), |
| 864 | sample: `{"my.metric","my.label"="v"} 1`, |
| 865 | }, |
| 866 | { |
| 867 | name: "text 1.0.0 honors explicit underscores", |
| 868 | accept: "text/plain;version=1.0.0;escaping=underscores", |
| 869 | accepted: DefaultAcceptedFormats(), |
| 870 | want: FmtText_1_0_0.WithEscapingScheme(model.UnderscoreEscaping), |
| 871 | sample: `my_metric{my_label="v"} 1`, |
| 872 | }, |
| 873 | { |
| 874 | name: "text 1.0.0 without escaping uses the default", |
| 875 | accept: "text/plain;version=1.0.0", |
| 876 | accepted: DefaultAcceptedFormats(), |
| 877 | want: FmtText_1_0_0.WithEscapingScheme(model.UnderscoreEscaping), |
| 878 | sample: `my_metric{my_label="v"} 1`, |
| 879 | }, |
| 880 | { |
| 881 | name: "higher quality legacy text wins without inheriting escaping", |
| 882 | accept: "text/plain;version=1.0.0;escaping=allow-utf-8;q=0.4,text/plain;version=0.0.4;q=0.8", |
| 883 | accepted: DefaultAcceptedFormats(), |
| 884 | want: FmtText.WithEscapingScheme(model.UnderscoreEscaping), |
| 885 | sample: `my_metric{my_label="v"} 1`, |
| 886 | }, |
| 887 | { |
| 888 | name: "caller can restrict support to legacy text", |
| 889 | accept: prometheusAccept, |
| 890 | accepted: []Format{FmtText}, |
| 891 | want: FmtText.WithEscapingScheme(model.UnderscoreEscaping), |
| 892 | sample: `my_metric{my_label="v"} 1`, |
| 893 | }, |
| 894 | } |
| 895 | for _, accept := range []string{"", "text/plain", "*/*", "application/json", "text/plain;version=9.9.9"} { |
| 896 | tests = append(tests, testCase{ |
| 897 | name: "legacy fallback for " + accept, |
| 898 | accept: accept, |
| 899 | accepted: DefaultAcceptedFormats(), |
nothing calls this directly
no test coverage detected