Class: Fluent::Plugin::AzureStorageGen2Output

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_azurestorage_gen2.rb

Defined Under Namespace

Classes: Compressor, GzipCompressor, JsonCompressor, TextCompressor

Constant Summary collapse

DEFAULT_FORMAT_TYPE =
"out_file"
URL_DOMAIN_SUFFIX =
'.dfs.core.windows.net'
ACCESS_TOKEN_API_VERSION =
"2018-02-01"
ABFS_API_VERSION =
"2018-11-09"
AZURE_BLOCK_SIZE_LIMIT =
4 * 1024 * 1024 - 1

Instance Method Summary collapse

Constructor Details

#initializeAzureStorageGen2Output

Returns a new instance of AzureStorageGen2Output.



17
18
19
20
# File 'lib/fluent/plugin/out_azurestorage_gen2.rb', line 17

def initialize
    super
    @compressor = nil
end

Instance Method Details

#configure(conf) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fluent/plugin/out_azurestorage_gen2.rb', line 56

def configure(conf)
    compat_parameters_convert(conf, :buffer, :formatter, :inject)
    super

    begin
        @compressor = COMPRESSOR_REGISTRY.lookup(@store_as).new(:buffer_type => @buffer_type, :log => log)
    rescue => e
        log.warn "#{@store_as} not found. Use 'text' instead"
        @compressor = TextCompressor.new
    end
    @compressor.configure(conf)

    @formatter = formatter_create
      
    if @localtime
      @path_slicer = Proc.new {|path|
        Time.now.strftime(path)
      }
    else
      @path_slicer = Proc.new {|path|
        Time.now.utc.strftime(path)
      }
    end
      
    if @azure_container.nil?
      raise Fluent::ConfigError, "azure_container is needed"
    end

    @azure_storage_path = ''
    @last_azure_storage_path = ''
    @current_index = 0
    if @store_as.nil? || @store_as == "none"
        @blob_content_type = "text/plain"
        @final_file_extension = @file_extension
    else
        @blob_content_type = @compressor.content_type
        @final_file_extension = @compressor.ext
    end

end

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/fluent/plugin/out_azurestorage_gen2.rb', line 97

def multi_workers_ready?
    true
end

#startObject



101
102
103
104
105
# File 'lib/fluent/plugin/out_azurestorage_gen2.rb', line 101

def start
    setup_access_token
    ensure_container
    super
end

#write(chunk) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/fluent/plugin/out_azurestorage_gen2.rb', line 107

def write(chunk)
     = chunk.
    if @store_as.nil? || @store_as == "none"
        raw_data=''
        generate_log_name(, @current_index)
        if @last_azure_storage_path != @azure_storage_path
            @current_index = 0
            generate_log_name(, @current_index)
        end
        chunk.each do |emit_time, record|
            if @message_field.nil? || @message_field.empty?
                raw_data << "#{Yajl.dump(record)}\n"
            elsif record.key?(@message_field)
                line = record[@message_field].chomp
                raw_data << "#{line}\n"
            end
        end
        raw_data = raw_data.chomp
        unless raw_data.empty?
            upload_blob(raw_data, )
        end
        @last_azure_storage_path = @azure_storage_path
    else
        tmp = Tempfile.new("azure-")
        begin
            @compressor.compress(chunk, tmp)
            tmp.close
            generate_log_name(, @current_index)
            if @last_azure_storage_path != @azure_storage_path
                @current_index = 0
                generate_log_name(, @current_index)
            end
            log.debug "Start uploading temp file: #{tmp.path}"
            content = File.open(tmp.path, 'rb') { |file| file.read }
            upload_blob(content, )
            @last_azure_storage_path = @azure_storage_path
        ensure
            tmp.unlink
        end
    end

end