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

feat: Add a display name parameter #166

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

Glutexo
Copy link
Contributor

@Glutexo Glutexo commented Feb 12, 2024

Enhancement:
A new rhc_insights.display_name parameter.

Reason:
The display name is a value managed by Insights Client. It is visible in the Host-Based Inventory and is used as the main visible name in the UI to identify a host and search for it.

Result:
The new rhc_insights.display_name parameter sets the display name of the host. This value is written to the Insights Client config file and also set directly by a --display-name command. When marked as absent or on unregistration, the value is removed from the config file.

Issue Tracker Tickets (Jira or BZ if any):
https://issues.redhat.com/browse/CCT-13

@richm richm changed the title CCT-13 Add a display name parameter feat: Add a display name parameter Feb 12, 2024
tasks/insights-client.yml Outdated Show resolved Hide resolved
Copy link
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

seems a good start; please don't forget a test for it

README.md Outdated Show resolved Hide resolved
@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 13, 2024

Fixed the typos. Going to add the tests.

@Glutexo Glutexo marked this pull request as ready for review February 13, 2024 14:28
@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 13, 2024

I added the tests, so I am opening the pull request for a review.

Copy link
Contributor

@DuckBoss DuckBoss left a comment

Choose a reason for hiding this comment

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

I had a quick look over -- make sure the tests are referencing display_name instead of ansible_host. I know the tests are near-identical to ansible_host tests but I'm assuming leaving the fields as ansible_host was unintentional.
(Edit: see below for specific lines highlighted by richm)

I can test these changes shortly after you push the changes 👍

@richm
Copy link
Contributor

richm commented Feb 15, 2024

lgtm - @ptoscano @DuckBoss ?

Copy link
Contributor

@DuckBoss DuckBoss left a comment

Choose a reason for hiding this comment

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

LGTM, let's revisit wrt --display-name after changes to insights-client.

Copy link
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

  • {state: absent}: the display name is unset in the insights-client config file; please note that Host Based Inventory is not updated

I don't think this is a good approach: the user will see that the insights-client configuration was changed (good), but not what is in Inventory (bad), leading the users to think that their operation succeeded. If it is not possible to "unset" (i.e. reset to the hostname) the display name, then the role ought to not allow the users to do this.

Hence:

  • drop the handling of {state: absent} altogether
  • handle empty values as null, documenting this behaviour as limitation in the underlying tooling (insights-client)

Copy link
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

@Glutexo not sure why I'm requesting to review again; see my previous comment on 'state: absent'

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 16, 2024

I spotted an issue when display_name is set to an empty string:

  • display_name= gets written into the config file, causing the display name not to be updated. It is equivalent to a missing value in the file.
  • The Client is run with --display_name=, which is ignored and causes a regular connection to run. That is an unwanted and resource-heavy process.

It is the same problem as I found in #155 (review). Since this pull request already has an approval from Jason, it may make sense to merge it as it is and fix the bug for both parameters at the same time in a follow-up pull request. If you think it’s worth including in this one, I‘ll push the fix.

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 16, 2024

@ptoscano

The {state: absent} is however the only way how to remove the value from the config file, causing it at least not to be overwritten on collection. It is not an ideal solution, but as long as it’s documented it at least provides the user with an additional option.

Moreover, the non-ideal state that may cause confusion to the user (although the real behavior is documented) would only last until the Client is patched to support display name removal. That is true for the absence (😃) of {state: absent} too, though.

Still, I’d be more inclined to offer a way to clean the configuration, when there is one to add it.

What do you think, Pino?

@ptoscano
Copy link
Collaborator

The {state: absent} is however the only way how to remove the value from the config file, causing it at least not to be overwritten on collection.
[...]
Still, I’d be more inclined to offer a way to clean the configuration, when there is one to add it.

I'm not sure what would be the point of removing the value from the config file, if that will not reflect what is the state in Inventory.

Please see my previous comment which explains the situation as I see it: #166 (review)

Moreover, the non-ideal state that may cause confusion to the user (although the real behavior is documented) would only last until the Client is patched to support display name removal. That is true for the absence (😃) of {state: absent} too, though.

Yes, and I do not think the role ought to do operations that do not actually work. When insights-client (or actually insights-core) will be changed to allow resetting/unsetting the display name, then the role may be adapted to make use of that.

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 16, 2024

Since Pino requested changes on the pull request, I believe I can fix the empty string issue in this pull request. Pushed a new commit that causes the empty string to be treated as an empty value: the display name is ignored in that case.

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 16, 2024

@ptoscano

I think I understand. The role is not primarily intended to edit the Client config file. It uses the Client as a tool to perform changes in the Inventory and changes the config file so the configuration is consistent with the new state and doesn’t get reverted on the next collection. In that case, removing {state: absent} makes sense until the Client doesn’t support removing the display name from the Inventory.

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 16, 2024

Pushed a patch removing the {state: absent} value. If a user still tries to provide such value, it is converted to a string by Python (to {'state': 'absent'}, which causes error. I believe this is not something we need to cover, as this happens to other string values too.

README.md Show resolved Hide resolved
@ptoscano
Copy link
Collaborator

The role is not primarily intended to edit the Client config file. It uses the Client as a tool to perform changes in the Inventory and changes the config file so the configuration is consistent with the new state and doesn’t get reverted on the next collection.

Yes and no.

Take a step back: a role/playbook/module/etc is nothing more than a glorified/structured way to do operations and check their results. Whatever is done with Ansible, it can be run manually to get the same result.

In case of this role, its purpose is to create and maintain the connectivity of systems to Red Hat or Satellite, Insights included. If to do so some configuration files must be edited, then they are edited; if some command must be run, they are run; and so on.

In the specific case of this option, we need to ensure that insights-client will keep reporting the configured display name to the connected Inventory. Since querying manually Inventory would sort of "go around" the purpose of insights-client, then we tell insights-client which display name to use by writing it in the config file, and then running insights-client as needed to ensure Inventory is up-to-date with the wanted configuration.

Copy link
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

The changes seem fine to me now, thanks!

The only thing to check would be what Rich mentioned (and I added some notes) on the documentation about the lack of "unset"; let's include what I wrote (or something along those lines), if that looks OF for you.

Since the time for merging is closer, please rebase and squash the commits into one with a proper commit message for it.

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 21, 2024

I added a note on the default display name value to the documentation. I found the suggested wording a bit too verbose, so I tried to shorten it a bit.

@ptoscano
Copy link
Collaborator

please rebase and squash the commits into one with a proper commit message for it.

this still needs to be done

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 21, 2024

Squashed the branch into a single commit and force-pushed.

@richm
Copy link
Contributor

richm commented Feb 21, 2024

[citest]

The new rhc.display_name parameter allows to set a display name, a
value used to identify the host in the Host-Based Inventory. Unlike
Ansible host name, display name can’t be reset to default by Insights
Client, thus the {state: absent} value is not supported.
@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 21, 2024

I realized that I added the empty string condition to fix a buggy behavior, but without a test.

I added a test verifying that setting rhc_insights.display_name to an empty string doesn’t change the value in the config file, just as a null doesn’t. Without the added condition, the test would fail, because the empty string would change the line in the config file to display_name=.

I didn’t test calling the insights-client, because that is not tested at all by any of the existing tests.

@ptoscano
Copy link
Collaborator

[citest]

@Glutexo
Copy link
Contributor Author

Glutexo commented Feb 21, 2024

From what I found that the Insights Client doesn’t send an empty display name, I am a bit afraid that adding support for the Client to reset the value in the Inventory would require a change on the Platform side. I will however verify, what is the actual behavior of sending various empty values of the display name.

Copy link
Collaborator

@ptoscano ptoscano left a comment

Choose a reason for hiding this comment

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

LGTM now -- thanks for the work on this!

@ptoscano ptoscano merged commit af343c0 into linux-system-roles:main Feb 21, 2024
17 checks passed
@Glutexo Glutexo deleted the display_name branch February 22, 2024 12:44
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.

None yet

4 participants