xk6-client-prometheus-remote
    Preparing search index...

    Function precompileLabelTemplates

    • Precompiles label templates for efficient metric generation.

      Compiling templates once and reusing them is more efficient than compiling on every call to Client.storeFromTemplates. Use this when you need to call Client.storeFromPrecompiledTemplates repeatedly with the same template structure.

      The returned object is opaque and can only be used with Client.storeFromPrecompiledTemplates.

      Parameters

      Returns PrecompiledLabelTemplates

      Precompiled label templates that can be reused across multiple calls

      import remote from 'k6/x/remotewrite';

      const template = {
      __name__: 'k6_generated_metric_${series_id/4}',
      series_id: '${series_id}',
      environment: 'production'
      };

      // Compile once during setup
      const compiled = remote.precompileLabelTemplates(template);

      const client = new remote.Client({ url: "https://..." });

      // Reuse in every iteration
      export default function() {
      client.storeFromPrecompiledTemplates(100, 200, Date.now(), 0, 100, compiled);
      }