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

BUG: helper code does not work if addon-name!=addon-rest-root #1333

Closed
livehybrid opened this issue Sep 5, 2024 · 3 comments
Closed

BUG: helper code does not work if addon-name!=addon-rest-root #1333

livehybrid opened this issue Sep 5, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@livehybrid
Copy link
Contributor

Description

Steps to recreate:

  1. ucc-gen init --addon-name TA-test-app --addon-display-name "Test API Collector for Splunk" --addon-input-name getStats --addon-rest-root "ta_test_api"
  2. ucc-gen build
  3. ucc-gen package
  4. Install app, create dummy account, create dummy input.
  5. Input fails.

Error:

2024-09-05 20:33:23,393 log_level=ERROR pid=5388 tid=MainThread file=conf_manager.py:get_log_level:546 | Failed to fetch configuration file TA-test-app_settings, taking INFO as log level.
2024-09-05 20:33:23,393 log_level=INFO pid=5388 tid=MainThread file=log.py:log_event:230 | action=started modular_input_name=test1
2024-09-05 20:33:23,514 log_level=ERROR pid=5388 tid=MainThread file=log.py:log_exception:355 | exc_l="my custom error type" Exception raised while ingesting data for demo_input:
Traceback (most recent call last):
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/client.py", line 1826, in __getitem__
    self.get(key)
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/client.py", line 1788, in get
    return super().get(name, owner, app, sharing, **query)
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/client.py", line 856, in get
    return self.service.get(path,
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/binding.py", line 321, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/binding.py", line 76, in new_f
    val = f(*args, **kwargs)
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/binding.py", line 730, in get
    response = self.http.get(path, all_headers, **query)
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/binding.py", line 1265, in get
    return self.request(url, {'method': "GET", 'headers': headers})
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/binding.py", line 1337, in request
    raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 404 Not Found -- TA-test-app_account does not exist

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/splunk/etc/apps/TA-test-app/lib/solnlib/conf_manager.py", line 457, in get_conf
    conf = self._confs[name]
  File "/opt/splunk/etc/apps/TA-test-app/lib/splunklib/client.py", line 1830, in __getitem__
    raise KeyError(key)
KeyError: 'TA-test-app_account'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/splunk/etc/apps/TA-test-app/bin/getStats_helper.py", line 68, in stream_events
    api_key = get_account_api_key(session_key, input_item.get("account"))
  File "/opt/splunk/etc/apps/TA-test-app/bin/getStats_helper.py", line 22, in get_account_api_key
    account_conf_file = cfm.get_conf("TA-test-app_account")
  File "/opt/splunk/etc/apps/TA-test-app/lib/solnlib/utils.py", line 153, in wrapper
    return func(*args, **kwargs)
  File "/opt/splunk/etc/apps/TA-test-app/lib/solnlib/conf_manager.py", line 459, in get_conf
    raise ConfManagerException(f"Config file: {name} does not exist.")
solnlib.conf_manager.ConfManagerException: Config file: TA-test-app_account does not exist.

The error looks to be caused because the helper code (./splunk_add_on_ucc_framework/templates/input.helper-init-template) has the wrong value in 2 places:

  • account_conf_file = cfm.get_conf("{{addon_name}}_account")
  • conf_name=f"{ADDON_NAME}_settings",

In these instances it should be addon_rest_root.

Currently the addon_rest_root isnt a variable written into the file like ADDON_NAME is, however there are times I would have found this helpful and sometimes end up adding this in myself, therefore it might be better to create a ADDON_REST_ROOT variable underneath ADDON_NAME (https://github.com/splunk/addonfactory-ucc-generator/blob/main/splunk_add_on_ucc_framework/templates/input.helper-init-template#L9) so that it can be used within the file by the developer if needed, and then updating conf_name=f"{ADDON_REST_ROOT}_settings" and account_conf_file = cfm.get_conf(f"{ADDON_REST_ROOT}_account") ?

What UCC version are you using?

ucc-gen version 5.49.0

Additional System Info

Python 3.9.15, MacOS Sequoia 15.0

@livehybrid livehybrid added bug Something isn't working triage Pending triage from maintainers labels Sep 5, 2024
@artemrys artemrys removed the triage Pending triage from maintainers label Sep 6, 2024
@artemrys
Copy link
Member

artemrys commented Sep 6, 2024

@livehybrid thanks for raising an issue, Hetang is already working on the similar ticket and it will be fixed and released in ~2 weeks time.

@hetangmodi-crest
Copy link
Contributor

The issue has been fixed, and I've tested it using the provided steps. The TA inputs are now working as expected.

hetangmodi-crest added a commit that referenced this issue Oct 1, 2024
**Issue number:** ADDON-74883, #1333 
## Summary

### Changes

> Changed the validations for name and restRoot field according to the
conventions specified in ADDON-74883. Additionally, the add-on will not
be built if the name in `globalConfig` does not match the name in
`app.manifest`.

### User experience

> User has to keep the same add-on name in `globalConfig` and
`app.manifest`, if the name does not match then add-on will not be
built. This is usually never the case unless the `app.manifest or name
in globalConfig is changed manually after initializing the add-on.

## Checklist

If your change doesn't seem to apply, please leave them unchecked.

* [x] I have performed a self-review of this change
* [x] Changes have been tested
* [x] Changes are documented
* [x] PR title follows [conventional commit
semantics](https://www.conventionalcommits.org/en/v1.0.0/)

---------

Co-authored-by: srv-rr-github-token <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: sgoral-splunk <[email protected]>
Co-authored-by: Artem Rys <[email protected]>
@hetangmodi-crest
Copy link
Contributor

The issue has been fixed, and the code has been merged. Hence, closing the issue. The fix would be available in v5.50.0 release.

srv-rr-github-token added a commit that referenced this issue Oct 2, 2024
# [5.50.0](v5.49.0...v5.50.0) (2024-10-02)

### Bug Fixes

* boolean values are converted to 1 and 0 only on configuration page ([#1347](#1347)) ([d0d0c11](d0d0c11))
* custom row loading on many tabs ([#1336](#1336)) ([f124b5e](f124b5e))
* **globalConfig:** update name and rest root convention ([#1335](#1335)) ([bdfa8c3](bdfa8c3)), closes [#1333](#1333)

### Features

* **dashboard:** add possibility to display CRITICAL log lvl in dashboard ([#1337](#1337)) ([d937986](d937986))
* option for configuring is_visible from globalConfig.json ([#1345](#1345)) ([04c80e3](04c80e3)), closes [#1334](#1334)
* provide support for Python 3.9 for OS-dependent libraries ([#1338](#1338)) ([5cfc889](5cfc889))
* restructure conf and spec file generation ([#1328](#1328)) ([bc6a36b](bc6a36b))
* restructure html file generation ([#1311](#1311)) ([ed2c2bd](ed2c2bd))
* restructure xml file generation ([#1312](#1312)) ([a171c8d](a171c8d))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants