fluent/fluentd · error · Fluent::ConfigError

time_slice_format only with %Y or %m is too long

Error message

time_slice_format only with %Y or %m is too long

What it means

The CompatParameters helper translates legacy v0.12 buffered-output config into the v0.14 <buffer> model; when time_slice_format is present, it must map the format's coarsest time directive to a timekey: %S→1s, %M→60s, %H→3600s, %d→86400s (compat_parameters.rb:152-158). A format containing only %Y and/or %m (or no time directive at all) describes a period of a month or year, which has no fixed duration and cannot be a chunk timekey, so conversion fails with this Fluent::ConfigError.

Source

Thrown at lib/fluent/plugin_helper/compat_parameters.rb:158

        hash = compat_parameters_copy_to_subsection_attributes(conf, buffer_params) do |compat_key, value|
          if compat_key == 'buffer_queue_full_action' && value == 'exception'
            'throw_exception'
          else
            value
          end
        end

        chunk_key = default_chunk_key

        if conf.has_key?('time_slice_format')
          chunk_key = 'time'
          hash['timekey'] = case conf['time_slice_format']
                            when /\%S/ then 1
                            when /\%M/ then 60
                            when /\%H/ then 3600
                            when /\%d/ then 86400
                            else
                              raise Fluent::ConfigError, "time_slice_format only with %Y or %m is too long"
                            end
          if conf.has_key?('localtime') || conf.has_key?('utc')
            if conf.has_key?('localtime') && conf.has_key?('utc')
              raise Fluent::ConfigError, "both of utc and localtime are specified, use only one of them"
            elsif conf.has_key?('localtime')
              hash['timekey_use_utc'] = !(Fluent::Config.bool_value(conf['localtime']))
            elsif conf.has_key?('utc')
              hash['timekey_use_utc'] = Fluent::Config.bool_value(conf['utc'])
            end
          end
        else
          if chunk_key == 'time'
            hash['timekey'] = 86400 # TimeSliceOutput.time_slice_format default value is '%Y%m%d'
          end
        end

        e = Fluent::Config::Element.new('buffer', chunk_key, hash, [])
        conf.elements << e

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Include a day or finer directive in time_slice_format, e.g. '%Y%m%d' (the v0.12 default) which maps to timekey 86400
  2. Better: drop the legacy parameters and configure the v0.14 buffer directly with <buffer time> timekey 2592000 </buffer>-style syntax for month-scale keys where genuinely needed
  3. Check for directive typos: only %S, %M, %H, %d are recognized by the converter
  4. If you maintain the plugin itself, consider warning users about unsupported granularities before the raise

Example fix

# before
<match out.**>
  @type file_with_compat
  time_slice_format %Y%m      # month granularity: no fixed timekey
  path /log/${time_slice}.log
</match>
# => time_slice_format only with %Y or %m is too long

# after
<match out.**>
  @type file_with_compat
  time_slice_format %Y%m%d   # day granularity -> timekey 86400
  path /log/${time_slice}.log
</match>
Defensive patterns

Strategy: validation

Validate before calling

fmt = '%Y%m%d' # from config
directive = fmt[/%(S|M|H|d)/]
raise 'time_slice_format lacks %S/%M/%H/%d; compat converter cannot derive a timekey' unless directive

Try / catch

begin
  plugin.configure(conf)
rescue Fluent::ConfigError => e
  if e.message.include?('time_slice_format')
    abort "use a day-or-finer directive in time_slice_format, or migrate to <buffer time> timekey"
  end
  raise
end

Prevention

When it happens

Trigger: A plugin using compat_parameters_convert(conf, :buffer) (or compat_parameters_buffer) whose config sets time_slice_format '%Y%m', '%Y', '%Y-%m', or e.g. '%j' — any value whose case-statement matches none of %S/%M/%H/%d. Hits at configure time, before any records are processed.

Common situations: v0.12-era configs migrated forward with monthly-sliced out_file-style paths; operators loosening time_slice_format to reduce file counts; a typo like '%0H' or lowercase '%h' evading every regex branch.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/6d1baa6874e11905. Report an issue: GitHub.