summaryrefslogtreecommitdiff
path: root/redfish-core/include/utils/time_utils.hpp
AgeCommit message (Collapse)AuthorFilesLines
2025-01-31Fix includesEd Tanous1-2/+4
Clang-tidy misc-include-cleaner appears to now be enforcing significantly more headers than previously. That is overall a good thing, but forces us to fix some issues. This commit is largely just taking the clang-recommended fixes and checking them in. Subsequent patches will fix the more unique issues. Note, that a number of new ignores are added into the .clang-tidy file. These can be cleaned up over time as they're understood. The majority are places where boost includes a impl/x.hpp and x.hpp, but expects you to use the later. include-cleaner opts for the impl, but it isn't clear why. Change-Id: Id3fdd7ee6df6c33b2fd35626898523048dd51bfb Signed-off-by: Ed Tanous <etanous@nvidia.com> Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
2025-01-24Move time_utils to compile unitEd Tanous1-410/+11
There's no reason for these functions to be in a header, and pulling them into a compile unit can reduce compile times overall. Tested: Unit tests pass (Good coverage) Change-Id: Ia6dc50d16bf2967e647a3c7437ba13bd7ab7ca3c Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-01-24Move to std::chronoEd Tanous1-0/+57
gcc-14 finally has calendar support. Move the existing helper functions over to using it, and deprecate the old methods (which involved a lot of magic numbers). The old methods are kept behind ifdefs for those still compiling against gcc-13 for the moment, but will be removed when we bump the requirements to gcc-14. Unrelated to the cleanup, this also saves 2Kb on the compressed binary size, presumably due to relying on implementations in libc++ instead of in bmcweb. Tested: Unit tests pass, good coverage. Change-Id: I739a3e876e84150dc654b9dff5eb05261b1daaf5 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2025-01-20Use SPDX identifiersEd Tanous1-0/+2
SPDX identifiers are simpler, and reduce the amount of cruft we have in code files. They are recommended by linux foundation, and therefore we should do as they allow. This patchset does not intend to modify any intent on any existing copyrights or licenses, only to standardize their inclusion. [1] https://www.linuxfoundation.org/blog/blog/copyright-notices-in-open-source-software-projects Change-Id: I935c7c0156caa78fc368c929cebd0f068031e830 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-10-14Reformat with Never-AlignTrailingComments styleMyung Bae1-4/+4
clang-format currently formats the codes to align the trailing comments of the consecutive lines via `AlignTrailingComments/Kind` as `Always` in `.clang-format` file. This could shift the comment lines by the neighboring code changes and also potentially mislead the `diff` of code changes. This commit is to keep the existing trailing comments as they were. Tested: - Check whitespace only - Code compiles & CI passes. Change-Id: I1c64d53572a81d5012aa748fe44478f80c271c5f Signed-off-by: Myung Bae <myungbae@us.ibm.com>
2024-10-09Support ProductionDate reportHieu Huynh1-0/+43
DSP0268 Redfish Data Model Specification provides ProductionDate property for various schema. phosphor-dbus-interface [1] also supports BuildDate property which we can map from FRU data, like `Board Manufacturer Date`. This adds code to support which gets the date from BuildDate property and report via Redfish. [1] https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/yaml/xyz/openbmc_project/Inventory/Decorator/Asset.interface.yaml#L16 Tested: Redfish Validator passes Signed-off-by: Hieu Huynh <hieuh@os.amperecomputing.com> Change-Id: Ie4ae564fa00218e7896f04ec61941fa92b23b912
2024-09-04Remove IWYU pragmasEd Tanous1-3/+0
These were added as part of d5c80ad9c07b94465d8ea62d2b6f87c30cac765e: test treewide: iwyu Since then, Nan hasn't been very active on the project, and to my knowledge, since the initial run, we've never used IWYU again. clang-include-cleaner seems to work well without needing these pragmas, and is what we're using, even if it's less useful than IWYU. Remove all mention of IWYU. Tested: Code compiles. Change-Id: I06feedeeac9a114f5bdec81d59ca83223efd8aa7 Signed-off-by: Ed Tanous <etanous@nvidia.com>
2024-06-19Clean up time utilsEd Tanous1-52/+18
We have std::format and c++20 now, this code can be simplified. Tested: Unit tests pass. Good coverage. Change-Id: Idc466d0ace9128a72bcd098290010a6a19da8536 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-04-11Remove logically dead codeEd Tanous1-6/+1
Stage::T is never set, so it can never happen. Remove it entirely. Found using static analysis. Tested: Unit tests pass, good coverage here Change-Id: I0dfb1aad5bef3ab4451df5e81794e56074f6e939 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-03-19Call systemd SetTime directlyEd Tanous1-1/+1
Internally inside phosphor-time-manager, the elapsed(uint64) dbus call just forwards the request directly to systemd after static casting to int64_t (signed). bmcweb should just call systemd directly, for several reasons. phosphor-timesyncd might block on other calls, given it's a single threaded blocking design, due to bugs like #264. Calling systemd directly means that calls that don't require phosphor networkd won't be blocked. Calling systemd directly allows bmcweb to drop some code that parses a date as int64_t, then converts it to uint64_t to fulfill the phosphor datetime interface. We can now keep int64_t all the way through. Calling systemd directly allows bmcweb to give a more specific error code in the case there NTP is enabled, registering a PropertyValueConflict error, instead of a 500 InternalError. Tested: Patching DateTime property with NTP enabled returns 400, PropertyValueConflict ``` curl -vvvv -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"DateTime":"2020-12-15T15:40:52+00:00"}' https://192.168.7.2/redfish/v1/Managers/bmc ``` Disabling NTP using the following command: ``` curl -vvvv -k --user "root:0penBmc" -H "Content-Type: application/json" -X PATCH -d '{"NTP":{"ProtocolEnabled":false}}' https://192.168.7.2/redfish/v1/Managers/bmc/NetworkProtocol ``` Allows the prior command to succeed. [1] https://github.com/openbmc/phosphor-time-manager/blob/5ce9ac0e56440312997b25771507585905e8b360/bmc_epoch.cpp#L126 Change-Id: I6fbb6f63e17de8ab847ca5ed4eadc2bd313586d2 Signed-off-by: Ed Tanous <ed@tanous.net>
2024-01-09Fix spelling mistakesEd Tanous1-2/+2
These were found with: codespell -w $(git ls-files | grep "\.[hc]\(pp\)\?$") At some point in the future, we might want to get this enabled in CI. Change-Id: Iccb57b2adfd06a2e177e99db2923fe4e8e329118 Signed-off-by: Ed Tanous <ed@tanous.net>
2023-09-08Simplify datetime parsingEd Tanous1-27/+1
This code as it stands pulls in the full datetime library from boost, including io, and a bunch of timezone code. The bmc doesn't make use of any of this, so we can rely on a much simplified version. Unfortunately for us, gcc still doesn't implement the c++20 std::chrono::parse[1]. There is a reference library available from [2] that backports the parse function to compilers that don't yet support it, and is the basis for the libc++ version. This commit opts to copy in the header as-written, under the assumption that we will never need to pull in new versions of this library, and will move to the std ersion as soon as it's available in the next gcc version. This commit simplifies things down to improve compile times and binary size. It saves ~22KB of compressed binary size, or about 3%. Tested: Unit tests pass. Pretty good coverage. [1] https://en.cppreference.com/w/cpp/chrono/parse [2] https://github.com/HowardHinnant/date/blob/master/include/date/date.h Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I706b91cc3d9df3f32068125bc47ff0c374eb8d87
2023-07-20Replace logging with std::formatEd Tanous1-6/+4
std::format is a much more modern logging solution, and gives us a lot more flexibility, and better compile times when doing logging. Unfortunately, given its level of compile time checks, it needs to be a method, instead of the stream style logging we had before. This requires a pretty substantial change. Fortunately, this change can be largely automated, via the script included in this commit under scripts/replace_logs.py. This is to aid people in moving their patchsets over to the new form in the short period where old patches will be based on the old logging. The intention is that this script eventually goes away. The old style logging (stream based) looked like. BMCWEB_LOG_DEBUG << "Foo " << foo; The new equivalent of the above would be: BMCWEB_LOG_DEBUG("Foo {}", foo); In the course of doing this, this also cleans up several ignored linter errors, including macro usage, and array to pointer deconstruction. Note, This patchset does remove the timestamp from the log message. In practice, this was duplicated between journald and bmcweb, and there's no need for both to exist. One design decision of note is the addition of logPtr. Because the compiler can't disambiguate between const char* and const MyThing*, it's necessary to add an explicit cast to void*. This is identical to how fmt handled it. Tested: compiled with logging meson_option enabled, and launched bmcweb Saw the usual logging, similar to what was present before: ``` [Error include/webassets.hpp:60] Unable to find or open /usr/share/www/ static file hosting disabled [Debug include/persistent_data.hpp:133] Restored Session Timeout: 1800 [Debug redfish-core/include/event_service_manager.hpp:671] Old eventService config not exist [Info src/webserver_main.cpp:59] Starting webserver on port 18080 [Error redfish-core/include/event_service_manager.hpp:1301] inotify_add_watch failed for redfish log file. [Info src/webserver_main.cpp:137] Start Hostname Monitor Service... ``` Signed-off-by: Ed Tanous <ed@tanous.net> Change-Id: I86a46aa2454be7fe80df608cb7e5573ca4029ec8
2023-07-06Simplify duration string parsingEd Tanous1-116/+121
The code that was here was quite complex, and relied on a number of c++ features that were hard to track. It also implemented a parser that would parse a given number multiple times. This commit replaces fromDurationString with a single pass, simpler parser, that doesn't rely on templates. It does this with a basic state machine, like one would see in any number of places. This allows the details section to be completely removed, as it can now be simply inlined. This results in a decrease of 1.1KB of the binary size of bmcweb. Note, C++20 now has an implementation of std::chrono::days, which obsoletes the need for redfish::time_utils::details::Days, so that conversion is done opportunistically. Tested: Unit tests pass. Pretty good coverage here. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8eb9bee9807cc102f3680105b39f4eed3bd2e73c
2023-05-11time-utils: fix clang-tidy warningPatrick Williams1-2/+2
The code already does size checking to ensure that buffer overruns are not done, so switch to using operator[] rather than pointer arithmetic. ``` ../redfish-core/include/utils/time_utils.hpp:71:19: error: unsafe pointer arithmetic [-Werror,-Wunsafe-buffer-usage] end = fmt.data() + pos; ``` Signed-off-by: Patrick Williams <patrick@stwcx.xyz> Change-Id: Iaabe82d7c1621dc27ad10288732609dfd0516d17
2023-05-11clang-format: copy latest and re-formatPatrick Williams1-2/+2
clang-format-16 has some backwards incompatible changes that require additional settings for best compatibility and re-running the formatter. Copy the latest .clang-format from the docs repository and reformat the repository. Change-Id: I75f89d2959b0f1338c20d72ad669fbdc1d720835 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
2023-01-23Break out set time function and unit test itEd Tanous1-0/+28
This function is something that's easily unit tested. Do it. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8d664c77ec4b3a9886128597449c5f9c041b86b3
2022-08-16Deduplicate leftZeroPaddingEd Tanous1-20/+11
We have two functions, leftZeroPadding, and padZeros that effectively do the same thing. leftZeroPadding has only one usage, and padZeros is debatably more efficient (given it doesn't need to construct an intermediate string). Move the one usage of leftZeroPadding to padZeros, and remove leftZeroPadding. One minor change needs to be made to padZeros, in that it needs to accept a long int instead of an int, given that some implementations use long int as their duration object. Tested: Unit tests pass. Good coverage on time functions. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Icbec45787ff940d098e18b61741b7476f4263558
2022-08-15Move time utils to be in one placeEd Tanous1-0/+185
We've accumulated several time utility functions in the http classes. Time isn't a core HTTP primitive, so http is not where those functions below. This commit moves all the time functions from the crow::utility namespace into the redfish::time_utils namespace, as well as moves the unit tests. No code changes where made to the individual functions, with the exception of changing the namespace on the unit tests. Tested: Unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8493375f60aea31899c84ae703e0f71a17dbdb73
2022-07-23test treewide: iwyuNan Zhou1-0/+4
These changes are done by running iwyu manually under clang14. Suppressed some obvious impl or details headers. Kept the recommended public headers. IWYU can increase readability, make maintenance easier, and avoid errors in some cases. See details in https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md. This commit also uses its best effort to correct obvious errors through iwyu pragma. See reference here: https://github.com/include-what-you-use/include-what-you-use#how-to-correct-iwyu-mistakes Tested: unit test passed. Signed-off-by: Nan Zhou <nanzhoumails@gmail.com> Change-Id: I983b6f75601707cbb0f2f04546c3362ff4ba7fee
2022-01-19Include what you useEd Tanous1-0/+5
Do a partial update from the include what you use tool. While ideally we'd be able to do this as part of CI, there's still quite a bit of noise in the output that requires manual intervention. Tested: Code compiles Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Iaaeb7a9199f64b5d6913c3abab4779b252768ed8
2022-01-12Enable init checkerEd Tanous1-1/+1
clang-tidy added cppcoreguidelines-init-variables as a check, which is something we already enforce to some extent, but getting CI to enforce it will help reviews move faster. Tested: Code compiles. Noop changes. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I7e10950de617b1d3262265572b1703f2e60b69d0
2022-01-12Enable bugprone widening checks in clangEd Tanous1-1/+2
Most of the errors we hit are simply places we need to explicitly increase the width of the integer. Luckily, these are few and far between. Tested: Code compiles, unit tests pass. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I617d87f3970ae773e0767bb2f20118fca2e71daa
2021-12-17Add GET method for TriggersLukasz Kazmierczak1-0/+20
Added GET method for retrieving details of individual Trigger searched by given Trigger name, details are extracted from Telemetry service Tested: - Added single Trigger and requested result from bmcweb via /redfish/v1/TelemetryService/Triggers/<triggername> - Added multiple Triggers numeric and discrete with various parameters (empty, non-empty), and requested results from bmcweb via /redfish/v1/TelemetryService/Triggers/<triggername> - Verified uris /redfish/v1/TelemetryService/Triggers/<triggername> by using Redfish-Service-Validator (all passed) Signed-off-by: Lukasz Kazmierczak <lukasz.kazmierczak@intel.com> Change-Id: I1c966b2f792324cc6f6a8784ad18a683e5ce7bd9
2021-07-13Make code compile with clang-13Ed Tanous1-1/+1
Clang-13 rightfully warns that the hasWebuiRoute variable isn't declared as static. This commit resolves that, and adds the static keyword so it can be used in multiple compile units. It also adds the static keyword to the privilege registry, and the inline keyword to many methods that now need it. clang-format is also updated to version 12 in parse_registies.py, as that's what CI uses, and what most people have installed. Tested: Followed clang-tidy instructions in README.md "bitbake bmcweb" step now succeeds. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Id43b13606754cb37a404799fce155599ac3a3240
2021-03-30Add POST and DELETE in MetricReportDefinitionsWludzik, Jozef1-2/+136
Added POST action in MetricReportDefinitions node to allow user to add new MetricReportDefinition. Using minimal set of MetricReportDefinition parameters from user bmcweb converts it to DBus call "AddReport" to Telemetry that serves as a backend for Redfish TelemetryService. Added DELETE request in MetricReportDefinitions node to allow user to remove report from Telemetry. Added conversion from string that represents duration format into its numeric equivalent. Added unit tests for conversion from and to Duration format. Tested: - Tested using witherspoon image on QEMU - Verified POST action in different cases: - all parameters are provided, new report is added to collection - some parameters are missing or invalid, user gets response with description of the issue - Verified that reports are removed on DELETE request - Verified that on invalid DELETE request user receives response with error - Verified time_utils::fromDurationString() - Succesfully passed RedfishServiceValidator.py Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com> Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com> Change-Id: I2fed96848594451e22fde686f8c066d7770cc65a
2021-02-24Fix the build on clang-11Ed Tanous1-1/+1
Clang tidy 11 got some really neat checks that do a much better job. Unfortunately, this, combined with the change in how std::executors has defined how callbacks should work differently in the past, which we picked up in 1.73, and now in theory we have recursion in a bunch of our IO loops that we have to break manually. In practice, this is unlikely to matter, as there's almost a 0% chance that we go through N thousand requests without ever starving the IO buffer. Other changes to make this build include: 1. Adding inline on the appropriate places where declared in a header. 2. Removing an Openssl call that did nothing, as the result was immediately overwritten. 3. Declaring the subproject dependencies as system dependencies, which silences the clang-tidy checks for those projects. Tested: Code builds again, clang-tidy passes Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ic11b1002408e8ac19a17a955e9477cac6e0d7504
2021-02-09Redfish TelemetryService schema implementationWludzik, Jozef1-0/+78
Now user is able to communicate with Telemetry service using Redfish. Added TelemetryService, MetricReports, MetricReportCollection, MetricReportDefinition and MetricReportDefinitionCollection nodes with GET method support. Added TelemetryService URI to root service. Implemented communication with backend - Telemetry: https://github.com/openbmc/telemetry Added schemes attributes that are supported by Telemetry service design, ref.: https://github.com/openbmc/docs/blob/master/designs/telemetry.md Change introduces function that converts decimal value into duration format that is described by ISO 8601 and Redfish specification. Tested: - Tested using romulus and s2600wf images on QEMU - Verified DBus method calls to Telemetry service from bmcweb - Verified bmcweb responses from new nodes in different cases: - Report collection is empty - Report collection is filled with artificial data - Telemetry service is disabled - Verified time_utils::toDurationString() output - Passed RedfishServiceValidator.py Signed-off-by: Wludzik, Jozef <jozef.wludzik@intel.com> Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com> Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com> Change-Id: Ie6b0b49f4ef5eeaef07d1209b6c349270c04d570