Skip to content
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

Create at most one PrintStream per log file. #661

Merged
merged 28 commits into from
Jan 2, 2017

Conversation

hwellmann
Copy link
Contributor

This avoids corrupted log files.

Fixes #652.

@codecov-io
Copy link

codecov-io commented Dec 17, 2016

Current coverage is 48.96% (diff: 59.50%)

Merging #661 into master will increase coverage by 1.59%

@@             master       #661   diff @@
==========================================
  Files           113        123    +10   
  Lines          5881       6333   +452   
  Methods           0          0          
  Messages          0          0          
  Branches       1020       1077    +57   
==========================================
+ Hits           2786       3101   +315   
- Misses         2850       2961   +111   
- Partials        245        271    +26   
Diff Coverage File Path
0% ...cker/access/hc/unix/UnixConnectionSocketFactory.java
0% ...maven/docker/access/hc/DockerAccessWithHcClient.java
0% ...java/io/fabric8/maven/docker/service/ServiceHub.java
0% new ...n/java/io/fabric8/maven/docker/VolumeRemoveMojo.java
0% .../fabric8/maven/docker/config/ImageConfiguration.java
0% new ...n/java/io/fabric8/maven/docker/VolumeCreateMojo.java
0% new .../fabric8/maven/docker/access/hc/unix/UnixSocket.java
0% ...fig/handler/compose/DockerComposeServiceWrapper.java
0% ...java/io/fabric8/maven/docker/AbstractDockerMojo.java
0% src/main/java/io/fabric8/maven/docker/StartMojo.java

Review all 28 files changed

Sunburst

Powered by Codecov. Last update f7008c3...b7aaed5

chonton and others added 5 commits December 17, 2016 12:10
AWS ECR key exchange
closes fabric8io#637

Signed-off-by: Chas Honton <chas@apache.org>
Signed-off-by: Chas Honton <chas@apache.org>
Copy link
Collaborator

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot ! I think we should implement the fix slightly differently, see my comment on LogDispatcher.

If you don't have time to change this this week, I could take this over to fix this.

return ps;
}

public static void closeLogs() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should be synchronized, too

@@ -37,15 +40,16 @@ public LogDispatcher(DockerAccess dockerAccess) {
}

public synchronized void trackContainerLog(String containerId, LogOutputSpec spec) throws FileNotFoundException {
LogGetHandle handle = dockerAccess.getLogAsync(containerId, new DefaultLogCallback(spec));
LogGetHandle handle = dockerAccess.getLogAsync(containerId, createLogCallback(spec));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a a fan of static imports as they dilute the real locations and I always search first in the current class when doing review. Could we refer to the static method via its class (LogCallbackFactory.createLogBack()) ? Even saves some lines.

@@ -145,7 +146,7 @@ public void startExecContainer(String containerId, LogOutputSpec outputSpec) thr
}

private ResponseHandler<Object> createExecResponseHandler(LogOutputSpec outputSpec) throws FileNotFoundException {
final LogCallback callback = new DefaultLogCallback(outputSpec);
final LogCallback callback = createLogCallback(outputSpec);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is closing this DefaultLogCallback() ?

}

public synchronized void untrackAllContainerLogs() {
closeLogs();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will close all streams from all LogDispatcher instances running. Not sure why it could be more than one, but at least we should avoid the mismatch with the LogCallbackFactory storing the stream in a static Map vs. using object instances for the LogDispatcher here. I would prefer to have LogCallbackFactory to be an object, too.

What's about the following idea: We simply allow DefaultLogCallback to reuse an existing printstream (i.e. we do the caching on a static field in DefaultLogCallback along with a usage count) and add a close() method to the callback so that the user can signal that he is done with logging ? In close() an the associated printstream's usage count will be decreased and if 0 then closed.

I think this kind of resource management makes more sense, also for potential future use cases. If you don't have the cycles to implement this, no problem, I could take over (as this is indeed an important fix to have). Also, a unit tests for DefaultLogCallback would be awesome then.

@hwellmann
Copy link
Contributor Author

Thanks for your feedback. I'll get back to this tomorrow...

@rhuss
Copy link
Collaborator

rhuss commented Dec 20, 2016 via email

@hwellmann
Copy link
Contributor Author

Reworked DefaultLogCallback with reference counting and added a test class. The LogCallbackFactory is gone.

Note: To test this in the context of my real-life project, I had to revert 7afec26, see #660.

Master appears to be broken, I'm seeing the same issue both on MacOS and Linux.

chonton and others added 15 commits December 21, 2016 09:47
Signed-off-by: Chas Honton <chas@apache.org>
Signed-off-by: Chas Honton <chas@apache.org>
added ability to explicitly via configuration to create named volumes
via <volumes><volume> configuration.
Example config
```xml
<volumes>
  <volume>
    <name>Volume Name</name>
    <driver>local</driver>
    <driverOpts>
      <driverOpt-key-name>driverOpt-value</driverOpt-key-name>
    </driverOpts>
    <labels>
    	<label-key>someValue</label-key>
      <com-github-fabric8-dmp-sample-volume>
        voluminous
      </com-github-fabric8-dmp-sample-volume>
    </labels>
  </volume>
</volumes>
```
Added a new volume sample
Added a new goal volume-create
minor formatting / spelling correction for intro.md

Signed-off-by: Tom Burton <Tom.Burton@Outlook.com>
Signed-off-by: Tom Burton <Tom.Burton@Outlook.com>
fabric8io#664 (review)
corrected spelling
corrected ascii-doc + formatting
code formatting

Signed-off-by: Tom Burton <Tom.Burton@Outlook.com>
fabric8io#664 (review)
corrected spelling
corrected ascii-doc + formatting
code formatting

Signed-off-by: Tom Burton <Tom.Burton@Outlook.com>
This is a cleanup of PR fabric8io#664 with the following major points tackled:

* Cleaned formatting
* Removed unneeded classes and service method for listing and getting volumes. This is not needed now and probablu not in the future.
* Fixed some Copy&Pase errors (like the default phase for 'volume-remove' which was the same as for 'volume-create'
* Fixed tests. Please note, that *no service method* should be adapted to be "testable". Especially do not introduce a non-private method only for this purpose and test this method instead of the offiical API. Modern Mock frameworks can deal with the the problems which are tried to be solved with this. Otherwise the API gets dilulted, more complicated, more maintenance, more coupled.
* Removed assert that do nothing.

Tests can be still improved for the service but its fine for now,

Next step is to add support for the PropertyHandler to allow configuration of the volumes also via properties.
Copy link
Collaborator

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot. I have some minor comments. If you dont mind I would fix them right now in order to proceed for a next release.

return printStream;
}

public void setPrintStream(PrintStream printStream) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesnt look like that this method is ever used. Also, removing this set-method makes the class immutable with respect to the printstream which is a good thing :)

@@ -91,6 +91,8 @@ public void fetchLogs() {
parseResponse(resp);
} catch (IOException exp) {
callback.error(exp.getMessage());
} finally {
callback.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ensure, that, when the callback is closed that this any call to the LogRequestors method is invalid (by throwing an exception).

Its also not so nice that the responsibilities for creating the callback (== caller of constructor of LogRequestor) and the one closing the callback (== the LogRequestor) are different objects. It would be much better when the LogRequestor has the complete control over allocation and closing of the print stream.

I suggest therefor to introduce a an LogCallback open() which allocates the stream instead of automatically allocating it in the constructor. Each method which can close a stream then would have to open it before.

@@ -224,6 +227,7 @@ public void finish() {
}
}
}
callback.close();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finish() is called in case of an exception but the callback.close() is also included in the finally clauses of the top level methods. This leads to closing a callback() twice which is probably not intended.

callback2.log(1, ts, "line 4");
callback2.close();

List<String> lines = Files.readAllLines(path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't use Java 8 and are still stuck to Java 7 for now (this might change in the future). So we need some other way to read all lines here.

This change is related to fabric8io#661 to make start / stop more symmetric

- removing Java 8 methods
- minor cosmetics
@rhuss
Copy link
Collaborator

rhuss commented Jan 2, 2017

@hwellmann I made some changes and would like to push it to this PR. Could you please grant me push permissions ? This is described here

@rhuss
Copy link
Collaborator

rhuss commented Jan 2, 2017

Sorry, my faul. Mispelled the target branch for the push.

@rhuss
Copy link
Collaborator

rhuss commented Jan 2, 2017

[merge]

@fusesource-ci fusesource-ci merged commit 79e2686 into fabric8io:master Jan 2, 2017
rgbj pushed a commit to rgbj/docker-maven-plugin that referenced this pull request Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants