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

Add location library to elastic-package #303

Merged
merged 18 commits into from
Apr 6, 2021

Conversation

fearful-symmetry
Copy link
Contributor

This is my attempt at "breaking up" #301 into more manageable parts. This is the first part, which is breaking up internal/install to create a locations library.

Right now, internal/install is taking on the role of managing the locations of all the files that elastic-package cares about. In an attempt to limit the duties of install to just installing things, and also to prepare for the internal/profile package that'll come right after this, we're adding a internal/location library that's solely responsible for owning where things are on the filesystem.

The fact that we have multiple methods for accessing some of the file paths is due to internal/install/install.go, which is the only library that cares about numerous file locations throughout ~/.elastic-package, so I decided to give it a provider.

I also chose not to touch internal/install/install.go here, as that file is particularly tied up with the newer profile library, and if I update that in the next PR with internal/profile, I won't have an ugly merge operation on my hands.

@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 30, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #303 updated

  • Start Time: 2021-04-06T16:39:09.880+0000

  • Duration: 21 min 3 sec

  • Commit: 0b44bdb

Test stats 🧪

Test Results
Failed 0
Passed 316
Skipped 1
Total 317

Trends 🧪

Image of Build Times

Image of Tests

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

I also chose not to touch internal/install/install.go here, as that file is particularly tied up with the newer profile library, and if I update that in the next PR with internal/profile, I won't have an ugly merge operation on my hands.

I understand your concerns regarding hard merge operation, but unfortunately this is the way how we should perform refactoring operations - it's not just about breaking the bigger PR into pieces. I think you should remove the refactored code as part of this PR.
Please remember that the PR shouldn't just introduce a dead code, but it must provide an added value for the end-user or at least be used by other internals.

internal/locations/locations.go Outdated Show resolved Hide resolved
internal/locations/locations.go Outdated Show resolved Hide resolved
@@ -8,15 +8,15 @@ import (
"github.com/pkg/errors"

"github.com/elastic/elastic-package/internal/files"
"github.com/elastic/elastic-package/internal/install"
"github.com/elastic/elastic-package/internal/locations"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if internal/locations is the correct place for this feature. This is a configuration that's strongly related to app configuration. I would be for placing it all together under internal/configuration, so we may have:
internal/configuration/locations
internal/configuration/profiles
internal/configuration/stack

In this case the goal would be transforming the internal/install into something more sophisticated that can deal with profiles and config extensions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. Should we do that as part of this PR, or later?

Copy link
Contributor

Choose a reason for hiding this comment

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

As you're adding locations, I think you can adapt it already.

internal/locations/locations.go Outdated Show resolved Hide resolved
@fearful-symmetry
Copy link
Contributor Author

I think you should remove the refactored code as part of this PR.

I'm not sure what you're referring to @mtojek ? Just keep locations/locations.go and remove the components that're swapped over to it?

internal/locations/locations.go Outdated Show resolved Hide resolved
@@ -8,15 +8,15 @@ import (
"github.com/pkg/errors"

"github.com/elastic/elastic-package/internal/files"
"github.com/elastic/elastic-package/internal/install"
"github.com/elastic/elastic-package/internal/locations"
Copy link
Contributor

Choose a reason for hiding this comment

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

As you're adding locations, I think you can adapt it already.

internal/locations/locations.go Outdated Show resolved Hide resolved
@mtojek
Copy link
Contributor

mtojek commented Mar 30, 2021

I'm not sure what you're referring to @mtojek ? Just keep locations/locations.go and remove the components that're swapped over to it?

Currently locations.go contains duplicated code from install. My point is to remove it from the old place and adjust all references to use locations.

@fearful-symmetry
Copy link
Contributor Author

@mtojek I moved around locations to a new configuration library. However, I wasn't sure what your thinking was behind putting stack in internal/configuration ? It doesn't seem quite as related to the functionality of profiles and locations

@mtojek
Copy link
Contributor

mtojek commented Mar 30, 2021

Cool! Please address also other comments and let me know when it's ready for re-review.

@fearful-symmetry fearful-symmetry requested a review from mtojek March 30, 2021 19:51
@fearful-symmetry
Copy link
Contributor Author

Alright, that should be everything.

@ycombinator
Copy link
Contributor

You might need to run make format to make CI happy.

@fearful-symmetry
Copy link
Contributor Author

Figured I was forgetting something...

@fearful-symmetry
Copy link
Contributor Author

@ycombinator can you tell if the CI issues are something I did? I'm trying to replicate it, the development files are there.

@ycombinator
Copy link
Contributor

@fearful-symmetry It looks like one of the system tests for the apache.access data set failed. You can see the failure in the Tests tab in Jenkins.

@ycombinator
Copy link
Contributor

I tried to reproduce the failure locally by building elastic-package from this PR and then running:

elastic-package stack up -d
$(elastic-package stack shellinit)
cd test/packages/apache
elastic-package test system

And the tests passed. So I'm going to tickle CI on this PR again and see what happens.

@ycombinator
Copy link
Contributor

jenkins, run the tests please

@ycombinator
Copy link
Contributor

Same test failed again. I'm going to try and dig into it more deeply locally and see if something turns up.

@mtojek
Copy link
Contributor

mtojek commented Mar 31, 2021

Ok, it seems that it's related to this PR, will try to reproduce it locally.

@mtojek
Copy link
Contributor

mtojek commented Mar 31, 2021

I think I found the problem, it seems to be related with volume's source.

Take a look at paths. The /tmp/service_logs/ path is mounted in elastic-agent's container:

    streams:
      - id: logfile-apache.access-ca17e851-8464-4100-a450-0733973daf00
        data_stream:
          dataset: apache.access
          type: logs
        paths:
          - /tmp/service_logs/access.log*
        exclude_files:
          - .gz$
        processors:
          - add_fields:
              target: ''
              fields:
                ecs.version: 1.5.0

The elastic-agent's container has the following definition:

  elastic-agent:
    image: ${ELASTIC_AGENT_IMAGE_REF}
    depends_on:
      elasticsearch:
        condition: service_healthy
      kibana:
        condition: service_healthy
    healthcheck:
      test: "sh -c 'grep \"Agent is starting\" /usr/share/elastic-agent/elastic-agent.log*'"
      retries: 30
      interval: 1s
    hostname: docker-fleet-agent
    environment:
    - "FLEET_ENROLL=1"
    - "FLEET_ENROLL_INSECURE=1"
    - "FLEET_INSECURE=1"
    - "FLEET_SETUP=1"
    - "FLEET_URL=http://kibana:5601"
    - "KIBANA_HOST=http://kibana:5601"
    volumes:
    - type: bind
      source: ../tmp/service_logs/
      target: /tmp/service_logs/

The volume's source is relative. I suspect that this path can't be found.

@fearful-symmetry
Copy link
Contributor Author

That's odd. That path makes sense, and nothing in the code that would change it.

@fearful-symmetry
Copy link
Contributor Author

Okay, I'm still baffled by the kibana errors. The path that @mtojek pointed to seems fine, the mount and files all exist and are pointing to the correct location. I can't see anything weird in the kibana install itself.

@mtojek
Copy link
Contributor

mtojek commented Apr 1, 2021

I think you can ignore these Kibana errors:

Regarding failed tests - I did a short test:

elastic-package stack up -v -d
docker exec -it <agent_container> /bin/bash
ls -la /tmp/service_logs/

The directory exists.

cd ~/go/src/github.com/elastic/integrations/packages/apache
elastic-package test system -v

The mounted directory will disappear, but it should be present and contain log files:

 ls -la /tmp/service_logs/
ls: cannot access /tmp/service_logs/: No such file or directory

@fearful-symmetry
Copy link
Contributor Author

@mtojek I can't seem to reproduce that. elastic-package test system -v fails to run because (I assume) all the kibana auth errors, and the directory still exists after. Could something be deleting the directory after the test?

@mtojek
Copy link
Contributor

mtojek commented Apr 1, 2021

elastic-package test system -v fails to run because (I assume) all the kibana auth errors, and the directory still exists after.

I meant the directory inside the agent's container (/tmp/service_logs).

@fearful-symmetry
Copy link
Contributor Author

I meant the directory inside the agent's container (/tmp/service_logs).

Yah, that's what I was referring to. I assume whatever is removing that directory isn't being run because the test system command is failing.

@mtojek
Copy link
Contributor

mtojek commented Apr 1, 2021

The system test runner fails because it expects some access logs to be present in that directory. Unfortunately the entire directory is deleted, but in fact the tool should delete only it's content. You can compare the behavior and paths in your PR and master build.

This can be a reference point: https://github.com/elastic/elastic-package/blob/master/internal/testrunner/runners/system/servicedeployer/compose.go#L55

or this: https://github.com/elastic/elastic-package/blob/master/internal/testrunner/runners/system/servicedeployer/compose.go#L127

EDIT:

Maybe the path which is passed doesn't exist. Sounds to me like something to debug.

@fearful-symmetry
Copy link
Contributor Author

fearful-symmetry commented Apr 1, 2021

Well, I'm still not sure what's up with the /tmp/service_logs thing. I ran the apache tests, and the logs exist inside the elastic-package-service_apache_1 container at /usr/local/apache2/logs, however, they don't exist inside the elastic-package-stack_elastic-agent_1 at /tmp/service_logs/

Here's what the mounts look like:

            {
                "Type": "bind",
                "Source": "/home/alexk/.elastic-package/tmp/service_logs",
                "Destination": "/usr/local/apache2/logs",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }

and

            {
                "Type": "bind",
                "Source": "/home/alexk/.elastic-package/tmp/service_logs",
                "Destination": "/tmp/service_logs",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }

@mtojek
Copy link
Contributor

mtojek commented Apr 1, 2021

So you can see that /home/alexk/.elastic-package/tmp/service_logs is the bridge between both containers. Could you verify that before starting the test system but after stack up, you can create a file on your host machine and it's still visible from inside of the agent container?
I assume you can do the same exercise after the test system.

@fearful-symmetry
Copy link
Contributor Author

fearful-symmetry commented Apr 1, 2021

Yah, something odd is going on inside that directory. Whatever I add from the docker host in /home/alexk/.elastic-package/tmp/service_logs doesn't appear on the container, and from inside the container I can't read or write to /tmp/service_logs, even though the directory itself exists.

I assume this is a config issue with docker-compose somehow, gonna tinker around after I get lunch.

@fearful-symmetry
Copy link
Contributor Author

@mtojek so, I did some more tinkering around, and it seems like the test system is breaking things. The bindmount inside the container works fine before, but once the Apache container starts up, the agent container can't seem to see anything inside the bindmount.

@fearful-symmetry
Copy link
Contributor Author

So, after the second container spins up, the link of the directory seems to get nuked:

before:

 67113534 drwxr-xr-x. 2 elastic-agent elastic-agent   6 Apr  2 18:07 service_logs

After:

 67113534 drwxr-xr-x. 0 elastic-agent elastic-agent   6 Apr  2 18:07 service_logs

@fearful-symmetry
Copy link
Contributor Author

The weird part is I can't reproduce this by manually starting up the docker container for apache:

docker-compose -f _dev/deploy/docker/docker-compose.yml --verbose up

@fearful-symmetry
Copy link
Contributor Author

Okay, think I figured it out. I was passing the wrong directory to the version check, so it was re-installing elastic-package every time.

return filepath.Join(loc.stackPath, serviceLogsDir)
}

// ConfigurationDir returns the configuration directory location
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// ConfigurationDir returns the configuration directory location
// configurationDir returns the configuration directory location

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

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

LGTM but please wait for @mtojek's review as well as he was actively reviewing this PR. Thanks!

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Nice! I think you can proceed with the next PR.

@mtojek
Copy link
Contributor

mtojek commented Apr 6, 2021

@fearful-symmetry Once this PR is merged could you please open a PR to elastic/integrations to get this change in (update dependency on elastic-package)? We need to be sure that it doesn't affect integrations.

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.

4 participants