Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Remove state provider #39

Merged
merged 3 commits into from Oct 28, 2019
Merged

Remove state provider #39

merged 3 commits into from Oct 28, 2019

Conversation

bonndan
Copy link
Collaborator

@bonndan bonndan commented Oct 26, 2019

This implements #37

I don't expect to you to fully understand the logic, it is sufficient to review the code for mistakes.

@bonndan bonndan added this to In progress in nivio via automation Oct 26, 2019
@bonndan bonndan added this to the 0.2 milestone Oct 26, 2019
Copy link
Member

@jpgoelz jpgoelz left a 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?

@bonndan
Copy link
Collaborator Author

bonndan commented Oct 28, 2019

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

@bonndan bonndan merged commit 8999121 into develop Oct 28, 2019
nivio automation moved this from In progress to Done Oct 28, 2019
@bonndan bonndan deleted the remove_state_provider branch October 28, 2019 15:28
nivio automation moved this from Done to Reviewer approved Oct 28, 2019
Copy link
Member

@Matthimatiker Matthimatiker left a 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.

Comment on lines +19 to +23
private static final List<SourceFormat> KNOWN_FORMATS;

static {
KNOWN_FORMATS = Arrays.asList(NIVIO, DOCKER_COMPOSE2, KUBERNETES, RANCHER1_PROMETHEUS);
}
Copy link
Member

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);

Copy link
Collaborator Author

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.

Comment on lines +34 to +37
} catch (MalformedURLException e) {
logger.error("Could not work on prometheus url {}", combine);
return new ArrayList<>();
}
Copy link
Member

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);
Copy link
Member

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<>();
Copy link
Member

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?

Copy link
Collaborator Author

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", ""));
Copy link
Member

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.

public void testSuccess() throws MalformedURLException {

String path = RootPath.get() + "/src/test/resources/example/rancher_prometheus_exporter.txt";
String prometheusExport = FileFetcher.readFile(new File(path));
Copy link
Member

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

@bonndan
Copy link
Collaborator Author

bonndan commented Oct 28, 2019

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.

Yes, a lot of code can be refactored, since some of it was used when JPA persistence was in place.

@bonndan bonndan moved this from Reviewer approved to Done in nivio Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
nivio
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants