Conversation
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.
While I cannot yet comprehend the logic, I also cannot find any obvious mistakes either.
I ran the program and it worked. I read all the files and checked the file changes. Anything, in particular, I should have been looking for?
There is an example File containing rancher1 Prometheus Export Data. I have served that file through nginx and it worked as expected. No more to do here |
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.
Looks reasonable, although I do not understand all the details 👍
The code contains an alarming number of manual type casts, which you might get rid of by improving the signatures with generic method parameters.
Items
contains a lot of static methods. Breaking these up code improve readability. E.g.
var filtered = Items.of(landscape).findAll(criteria);
By returning Items
, chaining would be possible and simplify working with subsets:
var filtered = Items.of(landscape).findAll(criteria).findAll(anotherCriteria);
Eventually, Items
might evolve into type-safe collection/query engine for Landscape items.
private static final List<SourceFormat> KNOWN_FORMATS; | ||
|
||
static { | ||
KNOWN_FORMATS = Arrays.asList(NIVIO, DOCKER_COMPOSE2, KUBERNETES, RANCHER1_PROMETHEUS); | ||
} |
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.
Isn't assignment on same line just the same, only simpler to read?
private static final List<SourceFormat> KNOWN_FORMATS = List.of(NIVIO, DOCKER_COMPOSE2, KUBERNETES, RANCHER1_PROMETHEUS);
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.
The current implementation is soon obsolete. #14 will replace it with something happening at runtime.
} catch (MalformedURLException e) { | ||
logger.error("Could not work on prometheus url {}", combine); | ||
return new ArrayList<>(); | ||
} |
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.
Should that happen? If that's a configuration error, it might be helpful to simply forward the exception (e.g. wrapping it into an IllegalStateException
).
.forEach(itemDescription -> { | ||
ItemDescription inMap = tmp.computeIfAbsent(itemDescription.getFullyQualifiedIdentifier(), ItemDescription::new); | ||
ItemDescriptionFactory.assignNotNull(inMap, itemDescription); | ||
}); | ||
}); | ||
|
||
} catch (IOException e) { | ||
logger.error("Failed to scrape " + target, e); |
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.
This could be anything, e.g. a full hard drive. Wrap and re-throw might be a better option here.
PrometheusScraper prometheusScraper = getScraper(); | ||
final Map<FullyQualifiedIdentifier, StatusItem> tmp = new HashMap<>(); | ||
final Map<FullyQualifiedIdentifier, ItemDescription> tmp = new HashMap<>(); |
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.
Is this some sort of cache?
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.
No, not intentionally. This state was necessary before when the class was responsible for collecting statuses only. The whole class could be merged with the ItemDescriptionFactory for rancher/prometheus.
if (metric.getLabels().getOrDefault("health_state", "").equals("unhealthy") && metric.getValue() > 0) { | ||
return new StatusDescription(StatusItem.HEALTH, Status.ORANGE, metric.getLabels().getOrDefault("health_state", "")); | ||
health_state = new StatusDescription(StatusItem.HEALTH, Status.ORANGE, metric.getLabels().getOrDefault("health_state", "")); |
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.
Perhaps you should stick with camelCase here.
src/test/java/de/bonndan/nivio/input/rancher1/PrometheusExporterTest.java
Show resolved
Hide resolved
public void testSuccess() throws MalformedURLException { | ||
|
||
String path = RootPath.get() + "/src/test/resources/example/rancher_prometheus_exporter.txt"; | ||
String prometheusExport = FileFetcher.readFile(new File(path)); |
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.
You might want to read resources
files from the class path. Most probably, this implementation depends on the working directory.
A construct like the following should work (I do not remember all the details):
getClass().getResourceAsInputStream("/example/rancher_prometheus_exporter.txt"); // convert this into a string
Yes, a lot of code can be refactored, since some of it was used when JPA persistence was in place. |
This implements #37
I don't expect to you to fully understand the logic, it is sufficient to review the code for mistakes.