@@ -21,14 +21,14 @@ import "github.com/armon/go-metrics"
2121// Extractor extracts known patterns from the key into metrics.Label for better metric grouping
2222// and to help avoid the limit of 500 custom metric descriptors per project
2323// (https://cloud.google.com/monitoring/quotas).
24- func Extractor (key []string ) ([]string , []metrics.Label , error ) {
24+ func Extractor (key []string , kind string ) ([]string , []metrics.Label , error ) {
2525 // Metrics documented at https://www.vaultproject.io/docs/internals/telemetry.html should be
2626 // extracted here into a base metric name with appropriate labels extracted from the 'key'.
2727 switch len (key ) {
2828 case 3 : // metrics of format: *.*.*
2929 // vault.database.<method>
3030 if key [0 ] == "vault" && key [1 ] == "database" {
31- return key [:2 ], []metrics.Label {
31+ return typeWrap ( key [:2 ], kind ) , []metrics.Label {
3232 {
3333 Name : "method" ,
3434 Value : key [2 ],
@@ -37,14 +37,14 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
3737 }
3838 // vault.token.create_root
3939 if key [0 ] == "vault" && key [1 ] == "token" && key [2 ] == "create_root" {
40- return key , nil , nil
40+ return typeWrap ( key , kind ) , nil , nil
4141 }
4242
4343 // vault.barrier.<method>
4444 // vault.token.<method>
4545 // vault.policy.<method>
4646 if key [0 ] == "vault" && (key [1 ] == "barrier" || key [1 ] == "token" || key [1 ] == "policy" ) {
47- return key [:2 ], []metrics.Label {
47+ return typeWrap ( key [:2 ], kind ) , []metrics.Label {
4848 {
4949 Name : "method" ,
5050 Value : key [2 ],
@@ -53,7 +53,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
5353 }
5454 // vault.<backend>.<method>
5555 if key [0 ] == "vault" && (key [2 ] == "put" || key [2 ] == "get" || key [2 ] == "delete" || key [2 ] == "list" ) {
56- return key [:2 ], []metrics.Label {
56+ return typeWrap ( key [:2 ], kind ) , []metrics.Label {
5757 {
5858 Name : "method" ,
5959 Value : key [2 ],
@@ -63,7 +63,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
6363 case 4 : // metrics of format: *.*.*.*
6464 // vault.route.<method>.<mount>
6565 if key [0 ] == "vault" && key [1 ] == "route" {
66- return key [:2 ], []metrics.Label {
66+ return typeWrap ( key [:2 ], kind ) , []metrics.Label {
6767 {
6868 Name : "method" ,
6969 Value : key [2 ],
@@ -76,7 +76,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
7676 }
7777 // vault.audit.<type>.*
7878 if key [0 ] == "vault" && key [1 ] == "audit" {
79- return []string {"vault" , "audit" , key [3 ]}, []metrics.Label {
79+ return typeWrap ( []string {"vault" , "audit" , key [3 ]}, kind ) , []metrics.Label {
8080 {
8181 Name : "type" ,
8282 Value : key [2 ],
@@ -85,7 +85,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
8585 }
8686 // vault.rollback.attempt.<mount>
8787 if key [0 ] == "vault" && key [1 ] == "rollback" && key [2 ] == "attempt" {
88- return key [:3 ], []metrics.Label {
88+ return typeWrap ( key [:3 ], kind ) , []metrics.Label {
8989 {
9090 Name : "mount" ,
9191 Value : key [3 ],
@@ -94,7 +94,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
9494 }
9595 // vault.<backend>.lock.<method>
9696 if key [0 ] == "vault" && key [2 ] == "lock" {
97- return key [:3 ], []metrics.Label {
97+ return typeWrap ( key [:3 ], kind ) , []metrics.Label {
9898 {
9999 Name : "method" ,
100100 Value : key [3 ],
@@ -104,7 +104,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
104104 // vault.database.<name>.<method>
105105 // note: there are vault.database.<method>.error counters. Those are handled separately.
106106 if key [0 ] == "vault" && key [1 ] == "database" && key [3 ] != "error" {
107- return key [:2 ], []metrics.Label {
107+ return typeWrap ( key [:2 ], kind ) , []metrics.Label {
108108 {
109109 Name : "name" ,
110110 Value : key [2 ],
@@ -117,7 +117,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
117117 }
118118 //ivault.database.<method>.error
119119 if key [0 ] == "vault" && key [1 ] == "database" && key [3 ] == "error" {
120- return []string {"vault" , "database" , "error" }, []metrics.Label {
120+ return typeWrap ( []string {"vault" , "database" , "error" }, kind ) , []metrics.Label {
121121 {
122122 Name : "method" ,
123123 Value : key [2 ],
@@ -127,7 +127,7 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
127127 case 5 :
128128 // vault.database.<name>.<method>.error
129129 if key [0 ] == "vault" && key [1 ] == "database" && key [4 ] == "error" {
130- return []string {key [0 ], key [1 ], key [4 ]}, []metrics.Label {
130+ return typeWrap ( []string {key [0 ], key [1 ], key [4 ]}, kind ) , []metrics.Label {
131131 {
132132 Name : "name" ,
133133 Value : key [2 ],
@@ -141,7 +141,22 @@ func Extractor(key []string) ([]string, []metrics.Label, error) {
141141 default :
142142 // unknown key pattern, keep it as-is.
143143 }
144- return key , nil , nil
144+ return typeWrap (key , kind ), nil , nil
145+ }
146+
147+ func typeWrap (key []string , kind string ) []string {
148+ out := []string {}
149+ for _ , a := range key {
150+ out = append (out , a )
151+ }
152+ switch kind {
153+ case "counter" :
154+ return append (out , kind )
155+ case "gauge" :
156+ return append (out , kind )
157+ default :
158+ return out
159+ }
145160}
146161
147162// Bucketer specifies the bucket boundaries that should be used for the given metric key.
0 commit comments