How to log multiple fields in EventSource - etw-eventsource

I am using EventSource to log event. I need to record 30 fields for one event. It works if I pass all 30 fields as string one by one as shown below. I was able to log those events. But when I trying to pass a string[] into the WriteEvent(). The isEnabled() returns false. Is there a better way to pass multiple fields into the WriteEvent() method?
The following is my source code for my event provider.
sealed class NemoTraceLoggingProvider : EventSource
{
public static NemoTraceLoggingProvider Log = new NemoTraceLoggingProvider();
[Event(1, Version = 12)]
public void SendTraceLoggingEvent(string Host, string Machine, string NemoVersion, string TraceId, string Operation, string HttpResult, string CallDuration, string Segment, string InputCells,
string InputTargetCells, string InputTargetContext, string IdentifyEntitySurfaceFormsIterations, string IdentifyEntitySurfaceFormsMaxDuration,
string IdentifyEntitySurfaceFormsInstancesCount, string ResolveMethod2Iterations, string ResolveMethod2MaxDuration,
string ResolveMethod2InstancesCount, string ResolveMethod3Iterations, string ResolveMethod3MaxDuration, string ResolveMethod3InstancesCount,
string ExtractPatternIterations, string ExtractPatternMaxDuration, string ExtractPatternInstancesCount, string NormalizeTextIterations,
string NormalizeTextMaxDuration, string NormalizeTextInstancesCount, string MaxDocumentTopics, string MaxSurfaceTopics, string MaxSurfaceWords,
string MaxTopicWords)
{
if (IsEnabled())
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("TraceLogging: event is send out");
Console.ResetColor();
WriteEvent(1, Host, Machine, NemoVersion, TraceId, Operation, HttpResult, CallDuration, Segment, InputCells,
InputTargetCells, InputTargetContext, IdentifyEntitySurfaceFormsIterations, IdentifyEntitySurfaceFormsMaxDuration,
IdentifyEntitySurfaceFormsInstancesCount, ResolveMethod2Iterations, ResolveMethod2MaxDuration,
ResolveMethod2InstancesCount, ResolveMethod3Iterations, ResolveMethod3MaxDuration, ResolveMethod3InstancesCount,
ExtractPatternIterations, ExtractPatternMaxDuration, ExtractPatternInstancesCount, NormalizeTextIterations,
NormalizeTextMaxDuration, NormalizeTextInstancesCount, MaxDocumentTopics, MaxSurfaceTopics, MaxSurfaceWords,
MaxTopicWords);
}
else
{
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("Not Enabled!!!");
Console.ResetColor();
}
}
}
}
Thanks!

Related

ArrayIndexOutOfBounds exception for an empty string on #RestQuery

I have a handler in my rest easy lamda application
with the url: http://localhost:8080/store/search/v1/suggest
public List<Map<String, Object>> storeSearch(
#RestHeader("id") String id,
#RestQuery final String q,
#RestQuery final String columns) {
if (StringUtils.isBlank(q)) {
logger.error("Search query is empty");
return Collections.EMPTY_LIST;
}
The app is doing well for below cases but failing if q is empty
http://localhost:8080/store/search/v1/suggest?q=ab
http://localhost:8080/store/search/v1/suggest
failing here
http://localhost:8080/store/search/v1/suggest?q=
Can you please suggest me what I am missing here.

Data is written to BigQuery but not in proper format

I'm writing data to BigQuery and successfully gets written there. But I'm concerned with the format in which it is getting written.
Below is the format in which the data is shown when I execute any query in BigQuery :
Check the first row, the value of SalesComponent is CPS_H but its showing 'BeamRecord [dataValues=[CPS_H' and In the ModelIteration the value is ended with a square braket.
Below is the code that is used to push data to BigQuery from BeamSql:
TableSchema tableSchema = new TableSchema().setFields(ImmutableList.of(
new TableFieldSchema().setName("SalesComponent").setType("STRING").setMode("REQUIRED"),
new TableFieldSchema().setName("DuetoValue").setType("STRING").setMode("REQUIRED"),
new TableFieldSchema().setName("ModelIteration").setType("STRING").setMode("REQUIRED")
));
TableReference tableSpec = BigQueryHelpers.parseTableSpec("beta-194409:data_id1.tables_test");
System.out.println("Start Bigquery");
final_out.apply(MapElements.into(TypeDescriptor.of(TableRow.class)).via(
(MyOutputClass elem) -> new TableRow().set("SalesComponent", elem.SalesComponent).set("DuetoValue", elem.DuetoValue).set("ModelIteration", elem.ModelIteration)))
.apply(BigQueryIO.writeTableRows()
.to(tableSpec)
.withSchema(tableSchema)
.withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED)
.withWriteDisposition(WriteDisposition.WRITE_TRUNCATE));
p.run().waitUntilFinish();
EDIT
I have transformed BeamRecord into MyOutputClass type using below code and this also doesn't work:
PCollection<MyOutputClass> final_out = join_query.apply(ParDo.of(new DoFn<BeamRecord, MyOutputClass>() {
private static final long serialVersionUID = 1L;
#ProcessElement
public void processElement(ProcessContext c) {
BeamRecord record = c.element();
String[] strArr = record.toString().split(",");
MyOutputClass moc = new MyOutputClass();
moc.setSalesComponent(strArr[0]);
moc.setDuetoValue(strArr[1]);
moc.setModelIteration(strArr[2]);
c.output(moc);
}
}));
It looks like your MyOutputClass is constructed incorrectly (with incorrect values). If you look at it, BigQueryIO is able to create rows with correct fields just fine. But those fields have wrong values. Which means that when you call .set("SalesComponent", elem.SalesComponent) you already have incorrect data in the elem.
My guess is the problem is in some previous step, when you convert from BeamRecord to MyOutputClass. You would get a result similar to what you're seeing if you did something like this (or some other conversion logic did this for you behind the scenes):
convert BeamRecord to string by calling beamRecord.toString();
if you look at BeamRecord.toString() implementation you can see that you're getting exactly that string format;
split this string by , getting an array of strings;
construct MyOutputClass from that array;
Pseudocode for this is something like:
PCollection<MyOutputClass> final_out =
beamRecords
.apply(
ParDo.of(new DoFn() {
#ProcessElement
void processElement(Context c) {
BeamRecord record = c.elem();
String[] fields = record.toString().split(",");
MyOutputClass elem = new MyOutputClass();
elem.SalesComponent = fields[0];
elem.DuetoValue = fields[1];
...
c.output(elem);
}
})
);
Correct way of doing something like this is to call getters on the record instead of splitting its string representation, along these lines (pseudocode):
PCollection<MyOutputClass> final_out =
beamRecords
.apply(
ParDo.of(new DoFn() {
#ProcessElement
void processElement(Context c) {
BeamRecord record = c.elem();
MyOutputClass elem = new MyOutputClass();
//get field value by name
elem.SalesComponent = record.getString("CPS_H...");
// get another field value by name
elem.DuetoValue = record.getInteger("...");
...
c.output(elem);
}
})
);
You can verify something like this by adding a simple ParDo where you either put a breakpoint and look at the elements in the debugger, or output the elements somewhere else (e.g. console).
I was able to resolve this issue using below methods :
PCollection<MyOutputClass> final_out = record40.apply(ParDo.of(new DoFn<BeamRecord, MyOutputClass>() {
private static final long serialVersionUID = 1L;
#ProcessElement
public void processElement(ProcessContext c) throws ParseException {
BeamRecord record = c.element();
String strArr = record.toString();
String strArr1 = strArr.substring(24);
String xyz = strArr1.replace("]","");
String[] strArr2 = xyz.split(",");

FileHelpers: The delimiter '|' can´t be found after the field

I have huge CSV file (1GB) which looks like that:
1140|2017|0213065852|2001|99|Ä‚/ŮŌçlš˝Ă_Âá'ÄǸ|-3858,18|4015,36|100,17|19,34|0,00|0,00|0,00|40,00|0,00|0,00|0,00|32,57|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|12|12|74|18|24620,65|11903,96|29385,35|10993,94|0,00|-2520,88|0|0100|301|02|0302|N|N|N| | |2001-12-27 00:00:00|N|1140|1313|BG4CSXF0| |2002-01-01 00:28:13| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
1140|2017|0213065852|2002|99|ľë¸Â‰_gÂýľ)Ľ¸ů_°Ë
…p'™m'î'Ä_|-3799,76|3982,22|461,66|1,48|0,00|0,00|0,00|0,00|0,00|0,00|0,00|100,23|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|27|43|189|20|40140,74|48835,00|69605,32|19312,00|0,00|-3427,87|0|0100|301|02|0303|N|N|N| | |2002-12-27 00:00:00|N|1140|1313|BG4CSXF0| |2003-01-01 01:35:56| |0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00|0,00
When I try to read this file using FileHelpers using following code:
FileHelperEngine engine = new FileHelperEngine(typeof(BGDTMDF));
BGDTMDF[] tab = (BGDTMDF[])engine.ReadFile(path);
I get an error:
The delimiter '|' can´t be found after the field 'MDF_SALDOS_MEDIOS' at line 2 (the record has less fields, the delimiter is wrong or the next field must be marked as optional).
My class looks like:
[DelimitedRecord("|")]
public class BGDTMDF
{
public string MDF_ENTIDAD;
public string MDF_CENTRO_ALTA;
public string MDF_CUENTA;
public string MDF_ANIO;
public string MDF_MES;
[FieldNullValue("def")]
public string MDF_SALDOS_MEDIOS;
[FieldNullValue("def")]
public string MDF_SALDO_DISPUE;
public string MDF_SALDO_MAX_DEU;
public string MDF_INTE_COBRAD;
public string MDF_INTE_PAGADO;
public string MDF_IMPU_RETENI;
}
(there is only part of this class (so huge).)
Any help?
My solution is mark all fileds in class as [FieldOptional].

How to handle null pointer exceptions in elasticsearch

I'm using elasticsearch and i was trying to handle the case when the database is empty
#SuppressWarnings("unchecked")
public <M extends Model> SearchResults<M> findPage(int page, String search, String searchFields, String orderBy, String order, String where) {
BoolQueryBuilder qb = buildQueryBuilder(search, searchFields, where);
Query<M> query = (Query<M>) ElasticSearch.query(qb, entityClass);
// FIXME Currently we ignore the orderBy and order fields
query.from((page - 1) * getPageSize()).size(getPageSize());
query.hydrate(true);
return query.fetch();
}
the error at return query.fetch();
i'm trying to implement a try and catch statement but it's not working, any one can help with this please?

VB 2010: How to index textbox (making it like slots)?

If the title isn't clear; I want to be able to select any character from textbox without making some complex loops-dependent code (I can do that one). For example, let's consider this text is entered in a textbox:
hello user!
I want some syntax when I tell to get me the index 1's value, it gives me "h", for index 5 = "o"... etc
So, anyone knows what's the right syntax, please help!
string can be directly indexed without any special code.
//from metadata
public sealed class String : IComparable, ICloneable, IConvertible, IComparable<string>, IEnumerable<char>, IEnumerable, IEquatable<string>
{
....
// Summary:
// Gets the character at a specified character position in the current System.String
// object.
//
// Parameters:
// index:
// A character position in the current string.
//
// Returns:
// A Unicode character.
//
// Exceptions:
// System.IndexOutOfRangeException:
// index is greater than or equal to the length of this object or less than
// zero.
public char this[int index] { get; }
....
}
dim str = "hello";
dim hchar = str(0);
dim echar = str(1);
dim lchar = str(2);
ect
Dim x As String = "Hello"
Console.Write(x.IndexOf("e")) 'Would return the position
Console.Write(x(x.IndexOf("e"))) 'Would return the character based upon the position
Console.Write(x(1)) 'Returns the character based at position 1 of the string
You can remove the Console.Write if you are using a WinForm.
TextBox1.Text = x(x.IndexOf("e"))
This should work.
Dim orig = "hello user!"
Dim res = Enumerable.Range(0,orig.Length).[Select](Function(i) orig.Substring(i,1))
So then you can do:
Dim x = res(0) 'x = "h"