Skip to content

Commit

Permalink
Add onLogstashEntryCreate interception point, add mode to saveAll
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Nov 10, 2024
1 parent 740b2e8 commit e192bfc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ component {
interceptorSettings = {
customInterceptionPoints : [
"cbElasticsearchPreSave",
"cbElasticsearchPostSave"
"cbElasticsearchPostSave",
"onLogstashEntryCreate"
]
};

Expand Down
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"Elasticsearch for the Coldbox Framework",
"author":"Ortus Solutions <info@ortussolutions.com",
"author":"Ortus Solutions <info@ortussolutions.com>",
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cbelasticsearch/@build.version@/cbelasticsearch-@build.version@+@build.number@.zip",
"version":"3.4.2",
"slug":"cbelasticsearch",
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `onLogstashEntryCreate` interception point, to allow influencing and additions to final log object
- Add `mode` argument to client `saveAll` method to allow for a `create` mode to be used for data streams

## [3.4.1] - 2024-09-26

### Added
Expand Down
19 changes: 16 additions & 3 deletions models/io/HyperClient.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,8 @@ component accessors="true" threadSafe singleton {
array function saveAll(
required array documents,
boolean throwOnError = false,
struct params = {}
struct params = {},
string mode = "update"
){
var requests = [];

Expand Down Expand Up @@ -1259,10 +1260,22 @@ component accessors="true" threadSafe singleton {
}
}

var opAction = { "#mode#" : { "_index" : doc.getIndex() } };

if( if( !isNull( doc.getId() ) ) ){
opAction[ mode ][ "_id" ] = doc.getId();
}

var docAction = { "doc" : memento };

if( mode == "update" ){
docAction[ "doc_as_upsert" ] = true;
}

requests.append(
[
{ "update" : { "_index" : doc.getIndex(), "_id" : doc.getId() } },
{ "doc" : memento, "doc_as_upsert" : true }
opAction,
docAction
],
true
);
Expand Down
3 changes: 3 additions & 0 deletions models/util/Util.cfc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
component accessors="true" singleton {

property name="appEnvironment" inject="box:setting:environment";
property name="interceptorService" inject="coldbox:InterceptorService";

/**
* Ensures a CF native struct is returned ( allowing for dot-notation )
Expand Down Expand Up @@ -158,6 +159,8 @@ component accessors="true" singleton {
}

generateLogEntrySignature( logObj );

interceptorService.announce( "onLogstashEntryCreate", { "entry" : logObj } );
}

/**
Expand Down

0 comments on commit e192bfc

Please sign in to comment.