-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(meshmetrics): profiles implementation (#9624)
* feat(meshmetric): implement metrics profiles Added interface over metrics mutators Signed-off-by: slonka <[email protected]> * feat(meshmetric): add first test Signed-off-by: slonka <[email protected]> * feat(meshmetric): add contains match type Signed-off-by: slonka <[email protected]> * feat(meshmetric): make check pass Signed-off-by: slonka <[email protected]> * feat(meshmetric): rename test case Signed-off-by: slonka <[email protected]> * feat(meshmetric): update golden files Signed-off-by: slonka <[email protected]> * feat(meshmetric): rewrite policy to yaml Signed-off-by: slonka <[email protected]> * feat(meshmetric): add tests for None and All profiles Signed-off-by: slonka <[email protected]> * feat(meshmetric): add tests for include Signed-off-by: slonka <[email protected]> * feat(meshmetric): add tests for exclude Signed-off-by: slonka <[email protected]> * feat(meshmetric): need to figure out why the mutator is not getting inside the metric family loop Signed-off-by: slonka <[email protected]> * feat(meshmetric): start rewriting otel mutator Signed-off-by: slonka <[email protected]> * feat(meshmetric): otel mutator compiles Signed-off-by: slonka <[email protected]> * feat(meshmetric): remove logs Signed-off-by: slonka <[email protected]> * feat(meshmetric): adjust example to make e2e pass Signed-off-by: slonka <[email protected]> * feat(meshmetric): make format work Signed-off-by: slonka <[email protected]> * feat(meshmetric): adjust one more log line Signed-off-by: slonka <[email protected]> * feat(meshmetric): remove profiles mutator since its not called for old flow Signed-off-by: slonka <[email protected]> * feat(meshmetric): rename function Signed-off-by: slonka <[email protected]> --------- Signed-off-by: slonka <[email protected]>
- Loading branch information
Showing
43 changed files
with
886 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package metrics | ||
|
||
import ( | ||
"io" | ||
|
||
io_prometheus_client "github.com/prometheus/client_model/go" | ||
"github.com/prometheus/common/expfmt" | ||
) | ||
|
||
type ( | ||
MetricsMutator func(in io.Reader, out io.Writer) error | ||
PrometheusMutator func(in map[string]*io_prometheus_client.MetricFamily) error | ||
MeshMetricMutator func(in io.Reader) (map[string]*io_prometheus_client.MetricFamily, error) | ||
) | ||
|
||
func AggregatedOtelMutator(metricsMutators ...PrometheusMutator) MeshMetricMutator { | ||
return func(in io.Reader) (map[string]*io_prometheus_client.MetricFamily, error) { | ||
var parser expfmt.TextParser | ||
metricFamilies, err := parser.TextToMetricFamilies(in) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, m := range metricsMutators { | ||
err := m(metricFamilies) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return metricFamilies, nil | ||
} | ||
} | ||
|
||
func AggregatedMetricsMutator(metricsMutators ...PrometheusMutator) MetricsMutator { | ||
return func(in io.Reader, out io.Writer) error { | ||
var parser expfmt.TextParser | ||
metricFamilies, err := parser.TextToMetricFamilies(in) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, m := range metricsMutators { | ||
err := m(metricFamilies) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
for _, metricFamily := range metricFamilies { | ||
if _, err := expfmt.MetricFamilyToText(out, metricFamily); err != nil { | ||
return err | ||
} | ||
if _, err := out.Write([]byte("\n")); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.