Load tries to import a Python module with the same name found in config.Name, searches for subclasses of the AgentCheck class and returns the corresponding Check
(senderManager sender.SenderManager, config integration.Config, instance integration.Data)
| 104 | // Load tries to import a Python module with the same name found in config.Name, searches for |
| 105 | // subclasses of the AgentCheck class and returns the corresponding Check |
| 106 | func (cl *PythonCheckLoader) Load(senderManager sender.SenderManager, config integration.Config, instance integration.Data) (check.Check, error) { |
| 107 | if rtloader == nil { |
| 108 | return nil, fmt.Errorf("python is not initialized") |
| 109 | } |
| 110 | moduleName := config.Name |
| 111 | // FastDigest is used as check id calculation does not account for tags order |
| 112 | configDigest := config.FastDigest() |
| 113 | |
| 114 | // Lock the GIL |
| 115 | glock, err := newStickyLock() |
| 116 | if err != nil { |
| 117 | return nil, err |
| 118 | } |
| 119 | defer glock.unlock() |
| 120 | |
| 121 | // Platform-specific preparation |
| 122 | if !agentConfig.Datadog.GetBool("win_skip_com_init") { |
| 123 | log.Debugf("Performing platform loading prep") |
| 124 | err = platformLoaderPrep() |
| 125 | if err != nil { |
| 126 | return nil, err |
| 127 | } |
| 128 | defer platformLoaderDone() //nolint:errcheck |
| 129 | } else { |
| 130 | log.Infof("Skipping platform loading prep") |
| 131 | } |
| 132 | |
| 133 | // Looking for wheels first |
| 134 | modules := []string{fmt.Sprintf("%s.%s", wheelNamespace, moduleName), moduleName} |
| 135 | var loadedAsWheel bool |
| 136 | |
| 137 | var name string |
| 138 | var checkModule *C.rtloader_pyobject_t |
| 139 | var checkClass *C.rtloader_pyobject_t |
| 140 | for _, name = range modules { |
| 141 | // TrackedCStrings untracked by memory tracker currently |
| 142 | moduleName := TrackedCString(name) |
| 143 | defer C._free(unsafe.Pointer(moduleName)) |
| 144 | if res := C.get_class(rtloader, moduleName, &checkModule, &checkClass); res != 0 { |
| 145 | if strings.HasPrefix(name, fmt.Sprintf("%s.", wheelNamespace)) { |
| 146 | loadedAsWheel = true |
| 147 | } |
| 148 | break |
| 149 | } |
| 150 | |
| 151 | if err = getRtLoaderError(); err != nil { |
| 152 | log.Debugf("Unable to load python module - %s: %v", name, err) |
| 153 | } else { |
| 154 | log.Debugf("Unable to load python module - %s", name) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // all failed, return error for last failure |
| 159 | if checkModule == nil || checkClass == nil { |
| 160 | log.Debugf("PyLoader returning %s for %s", err, moduleName) |
| 161 | return nil, err |
| 162 | } |
| 163 |
no test coverage detected