Skip to content

Optimize JSON metric extraction by reusing parsed data#419

Open
balookrd wants to merge 1 commit into
prometheus-community:masterfrom
balookrd:fix/json-exporter-dco
Open

Optimize JSON metric extraction by reusing parsed data#419
balookrd wants to merge 1 commit into
prometheus-community:masterfrom
balookrd:fix/json-exporter-dco

Conversation

@balookrd
Copy link
Copy Markdown

Motivation

  • Large raw JSON payloads (e.g. ~50MB) were repeatedly unmarshalled and had JSONPath expressions reparsed for every metric/label extraction, increasing CPU and GC pressure and slowing scrapes.

Description

  • Parse the raw payload once per scrape by calling json.Unmarshal in JSONMetricCollector.Collect and reuse the resulting interface{} for all extractions.
  • Add precompiled JSONPath parsers to JSONMetric (keyParser, valueParser, labelsParsers, timestampParser) and a compileJSONPaths helper to build them.
  • Change extractValue, extractLabels, and timestampMetric to operate on parsed interface{} data and use precompiled *jsonpath.JSONPath parsers, and avoid marshal/unmarshal round-trips for ObjectScrape items.
  • Compile JSONPath expressions when creating metrics in CreateMetricsList so parsing errors surface early and runtime can reuse parsers; modified files are exporter/collector.go and exporter/util.go.

Signed-off-by: Maksim Malykhin <balookrd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant