Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/

source "https://rubygems.org"

gemspec

8 changes: 4 additions & 4 deletions examples/apache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,32 @@
<record>
oci_la_global_metadata ${{<key1>: <value1>, <key2>:<value2>}}
oci_la_entity_id <LOGGING_ANALYTICS_ENTITY_OCID> # If same across sources. Else keep this in individual filters
oci_la_entity_type <LOGGING_ANALYTICS_ENTITY_TYPE> # If same across sources. Else keep this in individual filters
oci_la_entity_type <LOGGING_ANALYTICS_ENTITY_TYPE> # If same across sources. Else keep this in individual filters
</record>
</filter>

<filter oci.apacheError>
@type record_transformer
enable_ruby true
<record>
oci_la_metadata ${{<key1>: <value1>, <key2>:<value2>}}
oci_la_metadata ${{<key1>: <value1>, <key2>:<value2}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invalid change. revert.

oci_la_log_source_name <LOGGING_ANALYTICS_SOURCENAME>
oci_la_log_group_id <LOGGING_ANALYTICS_LOGGROUP_OCID>
oci_la_log_path "${record['tailed_path']}"
oci_la_timezone <TIMEZONE>
tag ${tag}
</record>
</filter>

<match oci.**>
@type oci-logging-analytics
namespace <YOUR_OCI_TENANCY_NAMESPACE>
# Auth config file details
config_file_location ~/.oci/config
profile_name DEFAULT
# Buffer Configuration
<buffer>
@type file
path /var/log
path /var/log
retry_forever true
disable_chunk_backup true
</buffer>
Expand Down
3 changes: 2 additions & 1 deletion fluent-plugin-oci-logging-analytics.gemspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
## Copyright (c) 2021, 2022 Oracle and/or its affiliates.
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
require_relative './lib/fluent/version/version'

lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "fluent-plugin-oci-logging-analytics"
spec.version = "2.0.6"
spec.version = Version::VERSION
spec.authors = ["Oracle","OCI Observability: Logging Analytics"]
spec.email = ["[email protected]"]

Expand Down
7 changes: 4 additions & 3 deletions lib/fluent/dto/logEvents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/

class LogEvents
attr_accessor :entityId, :entityType, :logSourceName, :logPath, :logRecords , :metadata
attr_accessor :entityId, :entityType, :logSourceName, :logPath, :logRecords , :metadata, :timezone
def initialize(lrpe_key, fluentd_records)
@metadata, @entityId, @entityType, @logSourceName, @logPath = lrpe_key
@metadata, @entityId, @entityType, @logSourceName, @logPath, @timezone = lrpe_key
@logRecords = fluentd_records.map{ |record|
record['message']
}
Expand All @@ -17,7 +17,8 @@ def to_hash
entityType: @entityType,
logSourceName: @logSourceName,
logPath: @logPath,
logRecords: @logRecords
logRecords: @logRecords,
timezone:@timezone
}.compact
end

Expand Down
4 changes: 4 additions & 0 deletions lib/fluent/enums/source.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Source
FLUENTD = :fluentd
KUBERNETES_SOLUTION = :kubernetes_solution
end
3 changes: 2 additions & 1 deletion lib/fluent/metrics/metricsLabels.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class MetricsLabels
attr_accessor :worker_id, :tag, :logGroupId, :logSourceName, :logSet, :invalid_reason, :records_valid, :records_per_tag, :latency
attr_accessor :worker_id, :tag, :logGroupId, :logSourceName, :logSet, :invalid_reason, :records_valid, :records_per_tag, :latency,:timezone
def initialize
@worker_id = nil
@tag = nil
Expand All @@ -10,5 +10,6 @@ def initialize
@records_valid = 0
@records_per_tag = 0
@latency = 0
@timezone = nil
end
end
71 changes: 64 additions & 7 deletions lib/fluent/plugin/out_oci-logging-analytics.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
## Copyright (c) 2021, 2022 Oracle and/or its affiliates.
## The Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/

require 'fluent/plugin/output'
require "benchmark"
require 'zip'
require 'yajl'
require 'yajl/json_gem'

# require 'tzinfo'
require 'logger'
require_relative '../dto/logEventsJson'
require_relative '../dto/logEvents'
require_relative '../metrics/prometheusMetrics'
require_relative '../metrics/metricsLabels'
require_relative '../enums/source'

# Import only specific OCI modules to improve load times and reduce the memory requirements.
require 'oci/auth/auth'
Expand All @@ -36,7 +37,6 @@
require 'oci/waiter'
require 'oci/retry/retry'
require 'oci/object_storage/object_storage'

module OCI
class << self
attr_accessor :sdk_name
Expand Down Expand Up @@ -97,7 +97,8 @@ class OutOracleOCILogAnalytics < Output
config_param :zip_file_location, :string, :default => nil
desc 'The kubernetes_metadata_keys_mapping.'
config_param :kubernetes_metadata_keys_mapping, :hash, :default => {"container_name":"Container","namespace_name":"Namespace","pod_name":"Pod","container_image":"Container Image Name","host":"Node"}

desc 'opc-meta-properties'
config_param :collection_source, :string, :default => Source::FLUENTD

#****************************************************************
desc 'The http proxy to be used.'
Expand Down Expand Up @@ -256,6 +257,14 @@ def initialize_loganalytics_client()
else
@@loganalytics_client = OCI::LogAnalytics::LogAnalyticsClient.new(config: OCI::Config.new, signer: instance_principals_signer)
end
when "WorkloadIdentity"
workload_identity_signer = OCI::Auth::Signers::oke_workload_resource_principal_signer
if is_valid(@endpoint)
@@loganalytics_client = OCI::LogAnalytics::LogAnalyticsClient.new(config: OCI::Config.new, endpoint: @endpoint, signer: workload_identity_signer)
@@logger.info {"loganalytics_client initialised with endpoint: #{@endpoint}"}
else
@@loganalytics_client = OCI::LogAnalytics::LogAnalyticsClient.new(config: OCI::Config.new, signer: workload_identity_signer)
end
when "ConfigFile"
my_config = OCI::ConfigFileLoader.load_config(config_file_location: @config_file_location, profile_name: @profile_name)
if is_valid(@endpoint)
Expand Down Expand Up @@ -628,6 +637,8 @@ def group_by_logGroupId(chunk)
latency = 0
records_per_tag = 0



tag_metrics_set = Hash.new
logGroup_labels_set = Hash.new

Expand All @@ -637,8 +648,8 @@ def group_by_logGroupId(chunk)
tags_per_logGroupId = Hash.new
tag_logSet_map = Hash.new
tag_metadata_map = Hash.new
timezoneValuesByTag = Hash.new
incoming_records = 0

chunk.each do |time, record|
incoming_records += 1
metricsLabels = MetricsLabels.new
Expand Down Expand Up @@ -722,6 +733,8 @@ def group_by_logGroupId(chunk)
end
next
end

# metricsLabels.timezone = record["oci_la_timezone"]
metricsLabels.logGroupId = record["oci_la_log_group_id"]
metricsLabels.logSourceName = record["oci_la_log_source_name"]
if record["oci_la_log_set"] != nil
Expand Down Expand Up @@ -770,6 +783,25 @@ def group_by_logGroupId(chunk)
tags_per_logGroupId[record["oci_la_log_group_id"]] = record["tag"]
end
end
# validating the timezone field
if !timezoneValuesByTag.has_key?(record["tag"])
begin
timezoneIdentifier = record["oci_la_timezone"]
unless is_valid(timezoneIdentifier)
record["oci_la_timezone"] = nil
else
isTimezoneExist = timezone_exist? timezoneIdentifier
unless isTimezoneExist
@@logger.warn { "Invalid timezone '#{timezoneIdentifier}', using default UTC." }
record["oci_la_timezone"] = "UTC"
end

end
timezoneValuesByTag[record["tag"]] = record["oci_la_timezone"]
end
else
record["oci_la_timezone"] = timezoneValuesByTag[record["tag"]]
end

records << record
ensure
Expand Down Expand Up @@ -916,6 +948,14 @@ def write(chunk)
end
end
end
def timezone_exist?(tz)
begin
TZInfo::Timezone.get(tz)
return true
rescue TZInfo::InvalidTimezoneIdentifier
return false
end
end

# Each oci_la_log_set will correspond to a separate file in the zip
# Only MAX_FILES_PER_ZIP files are allowed per zip.
Expand Down Expand Up @@ -958,6 +998,21 @@ def get_logSets_map_per_logGroupId(oci_la_log_group_id,records_per_logGroupId)

# takes a fluentD chunk and converts it to an in-memory zipfile, populating metrics hash provided
# Any exception raised is passed into the metrics hash, to be re-thrown from write()
def getCollectionSource(input)
collections_src = []
if !is_valid input
collections_src.unshift("source:#{Source::FLUENTD}")
else
if input == Source::FLUENTD.to_s or input == Source::KUBERNETES_SOLUTION.to_s
collections_src.unshift("source:#{input}")
else
# source not define ! using default source 'fluentd'
collections_src.unshift("source:#{Source::FLUENTD}")
end
end
collections_src
end

def get_zipped_stream(oci_la_log_group_id,oci_la_global_metadata,records_per_logSet_map)
begin
current, = Time.now
Expand All @@ -970,8 +1025,9 @@ def get_zipped_stream(oci_la_log_group_id,oci_la_global_metadata,records_per_log
record['oci_la_metadata'],
record['oci_la_entity_id'],
record['oci_la_entity_type'],
record['oci_la_log_source_name'] ,
record['oci_la_log_path']
record['oci_la_log_source_name'],
record['oci_la_log_path'],
record['oci_la_timezone']
]}.map { |lrpe_key, records_per_lrpe|
number_of_records += records_per_lrpe.length
LogEvents.new(lrpe_key, records_per_lrpe)
Expand Down Expand Up @@ -1021,9 +1077,10 @@ def save_zip_to_local(oci_la_log_group_id, zippedstream, current_s)
# upload zipped stream to oci
def upload_to_oci(oci_la_log_group_id, number_of_records, zippedstream, metricsLabels_array)
begin
collection_src_prop = getCollectionSource @collection_source
error_reason = nil
error_code = nil
opts = {payload_type: "ZIP"}
opts = { payload_type: "ZIP", opc_meta_properties:collection_src_prop}

response = @@loganalytics_client.upload_log_events_file(namespace_name=@namespace,
logGroupId=oci_la_log_group_id ,
Expand Down
5 changes: 5 additions & 0 deletions lib/fluent/version/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Version
VERSION = "2.0.7".freeze
end