-
Notifications
You must be signed in to change notification settings - Fork 0
Added interfaces for time and data parsing #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
The head ref may contain hidden characters: "Common-interfaces-for-parsers(Task-\u21164)"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ | |
|
|
||
| import org.springframework.web.multipart.MultipartFile; | ||
| import ru.naumen.perfhouse.influx.InfluxDAO; | ||
| import ru.naumen.sd40.log.parser.GCParser.GCTimeParser; | ||
|
|
||
| /** | ||
| * Created by doki on 22.10.16. | ||
|
|
@@ -36,97 +35,75 @@ public static void parse(MultipartFile logs, String nameInfluxDB, String timeZon | |
| BatchPoints points = influxDAO.startBatchPoints(influxDb); | ||
| HashMap<Long, DataSet> data = new HashMap<>(); | ||
|
|
||
| TimeParser timeParser = new TimeParser(timeZone); | ||
| GCTimeParser gcTime = new GCTimeParser(timeZone); | ||
|
|
||
| switch (parseMode) | ||
| { | ||
| IDataParser parser; | ||
| ITimeParser timeParser; | ||
| switch (parseMode){ | ||
| case "sdng": | ||
| //Parse sdng | ||
| try (BufferedReader br = new BufferedReader(new InputStreamReader(logs.getInputStream()))) | ||
| { | ||
| String line; | ||
| while ((line = br.readLine()) != null) | ||
| { | ||
| long time = timeParser.parseLine(line); | ||
|
|
||
| if (time == 0) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| int min5 = 5 * 60 * 1000; | ||
| long count = time / min5; | ||
| long key = count * min5; | ||
|
|
||
| data.computeIfAbsent(key, k -> new DataSet()).parseLine(line); | ||
| } | ||
| } | ||
| parser = new SDNGParser(); | ||
| timeParser = new SDNGTimeParser(); | ||
| break; | ||
| case "gc": | ||
| //Parse gc log | ||
| try (BufferedReader br = new BufferedReader(new InputStreamReader(logs.getInputStream()))) | ||
| { | ||
| String line; | ||
| while ((line = br.readLine()) != null) | ||
| { | ||
| long time = gcTime.parseTime(line); | ||
|
|
||
| if (time == 0) | ||
| { | ||
| continue; | ||
| } | ||
|
|
||
| int min5 = 5 * 60 * 1000; | ||
| long count = time / min5; | ||
| long key = count * min5; | ||
| data.computeIfAbsent(key, k -> new DataSet()).parseGcLine(line); | ||
| } | ||
| } | ||
| parser = new GCParser(); | ||
| timeParser = new GCTimeParser(); | ||
| break; | ||
| case "top": | ||
| TopParser topParser = new TopParser(logs, data); | ||
| topParser.configureTimeZone(timeZone); | ||
| //Parse top | ||
| topParser.parse(); | ||
| //Parse top | ||
| parser = new TopParser(); | ||
| timeParser = new TopTimeParser(logs, data, timeZone); | ||
|
|
||
| break; | ||
| default: | ||
| throw new IllegalArgumentException( | ||
| "Unknown parse mode! Availiable modes: sdng, gc, top. Requested mode: " + parseMode); | ||
| } | ||
| parse(data, timeZone, logs, parser, timeParser); | ||
|
|
||
| if (traceCheck) | ||
| { | ||
| if (traceCheck){ | ||
| System.out.print("Timestamp;Actions;Min;Mean;Stddev;50%%;95%%;99%%;99.9%%;Max;Errors\n"); | ||
| } | ||
| data.forEach((k, set) -> | ||
| { | ||
| data.forEach((k, set) ->{ | ||
| ActionDoneParser dones = set.getActionsDone(); | ||
| dones.calculate(); | ||
| ErrorParser erros = set.getErrors(); | ||
| if (traceCheck) | ||
| { | ||
| if (traceCheck){ | ||
| System.out.print(String.format("%d;%d;%f;%f;%f;%f;%f;%f;%f;%f;%d\n", k, dones.getCount(), | ||
| dones.getMin(), dones.getMean(), dones.getStddev(), dones.getPercent50(), dones.getPercent95(), | ||
| dones.getPercent99(), dones.getPercent999(), dones.getMax(), erros.getErrorCount())); | ||
| } | ||
| if (!dones.isNan()) | ||
| { | ||
| if (!dones.isNan()){ | ||
| influxDAO.storeActionsFromLog(points, influxDb, k, dones, erros); | ||
| } | ||
|
|
||
| GCParser gc = set.getGc(); | ||
| if (!gc.isNan()) | ||
| { | ||
| if (!gc.isNan()){ | ||
| influxDAO.storeGc(points, influxDb, k, gc); | ||
| } | ||
|
|
||
| TopData cpuData = set.cpuData(); | ||
| if (!cpuData.isNan()) | ||
| { | ||
| if (!cpuData.isNan()){ | ||
| influxDAO.storeTop(points, influxDb, k, cpuData); | ||
| } | ||
| }); | ||
| influxDAO.writeBatch(points); | ||
| } | ||
|
|
||
| private static void parse(HashMap<Long, DataSet> data, String timeZone, | ||
| MultipartFile logs, IDataParser dataParser, ITimeParser timeParser) | ||
| throws ParseException, IOException { | ||
| try (BufferedReader br = new BufferedReader(new InputStreamReader(logs.getInputStream()))){ | ||
| String line; | ||
| while ((line = br.readLine()) != null){ | ||
| long time = timeParser.parseTime(line); | ||
|
|
||
| if (time == 0){ | ||
| continue; | ||
| } | ||
|
|
||
| data.computeIfAbsent(time, k -> new DataSet()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут создается новый dataset, но никак не используется. Надо присвоить это значение в переменную, а переменную передать в метод следующей строки - parseLine. Измените сигнатуру у parseLine в DataParser, чтобы он принимал строку и текущий dataset. Тогда не будет проблем с пустым currentSet во всех парсерах |
||
| dataParser.parseLine(line); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package ru.naumen.sd40.log.parser; | ||
|
|
||
| import java.text.ParseException; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import java.util.Locale; | ||
| import java.util.TimeZone; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class GCTimeParser implements ITimeParser{ | ||
| private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", | ||
| new Locale("ru", "RU")); | ||
|
|
||
| private static final Pattern PATTERN = Pattern | ||
| .compile("^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}.\\d{3}\\+\\d{4}).*"); | ||
|
|
||
| public GCTimeParser(){ | ||
| DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT")); | ||
| } | ||
|
|
||
| public GCTimeParser(String timeZone){ | ||
| DATE_FORMAT.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| } | ||
|
|
||
| public long parseTime(String line) throws ParseException{ | ||
| Matcher matcher = PATTERN.matcher(line); | ||
| if (matcher.find()){ | ||
| Date parse = DATE_FORMAT.parse(matcher.group(1)); | ||
| return parse.getTime(); | ||
| } | ||
| return 0L; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package ru.naumen.sd40.log.parser; | ||
|
|
||
| import java.text.ParseException; | ||
|
|
||
| public interface IDataParser { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ActionDoneParser, ErrorParser, GCParser, TopParser - все они должны реализовывать этот интерфейс |
||
| public void parseLine(String line) throws ParseException; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package ru.naumen.sd40.log.parser; | ||
|
|
||
| import java.text.ParseException; | ||
|
|
||
| public interface ITimeParser { | ||
| public long parseTime(String line) throws ParseException; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GCTimeParser, TimeParser, а также у TopParser должен появиться свой парсер для времени - они должны реализовывать этот интерфейс
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Имеется в виду, что каждый из них(GCTimeParser, TimeParser, TopParser) будет должен реализовать интерфейс ITimeParser, или что будут существовать другие классы-парсеры?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Есть еще мысль сделать по аналогии с GCParser (где существует подкласс GCTimeParser) или наоборот, избавиться от этого подкласса... |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package ru.naumen.sd40.log.parser; | ||
|
|
||
|
|
||
| /** | ||
| * Created by doki on 22.10.16. | ||
| */ | ||
| public class SDNGParser implements IDataParser{ | ||
|
|
||
| private DataSet currentSet; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currentSet всегда null? |
||
|
|
||
| public void parseLine(String line){ | ||
| ErrorParser errors = currentSet.getErrors(); | ||
| ActionDoneParser actionsDone = currentSet.getActionsDone(); | ||
| errors.parseLine(line); | ||
| actionsDone.parseLine(line); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
раньше в каждом режиме (внутри каждого блока case) был вызов соответствующего данному режиму метода
parseGcLine для GC
parseLine для sdng
TopParser содержал этот цикл внутри себя.
Нужно убрать эти методы из DataSet (они всего лишь переадресуют вызов в соответствующий парсер) и прямо здесь вызывать конкретный парсер. Как вы его получите - это уже зависит от вашего решения.
Также задача была "убрать дублирование". Имелся в виду в основном цикл while, который обходит все строки файла. Он есть здесь два раза, он есть в TopParser. В конце должен остаться только один.