Skip to content

Commit 793667d

Browse files
committed
fix: get data Source API
1 parent 2272669 commit 793667d

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

pkg/cluster/environment/EnvironmentService.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import (
4646

4747
type EnvironmentService interface {
4848
FindOne(environment string) (*bean2.EnvironmentBean, error)
49-
GetDataSourceName(environment string) (string, error)
49+
GetDataSourceName(environment string) (dataSourceData DataSourceMetaData, err error)
5050
Create(mappings *bean2.EnvironmentBean, userId int32) (*bean2.EnvironmentBean, error)
5151
Update(mappings *bean2.EnvironmentBean, userId int32) (*bean2.EnvironmentBean, error)
5252
GetAllActive() ([]bean2.EnvironmentBean, error)
@@ -106,25 +106,33 @@ func NewEnvironmentServiceImpl(environmentRepository repository.EnvironmentRepos
106106
}
107107
}
108108

109-
func (impl EnvironmentServiceImpl) GetDataSourceName(environment string) (string, error) {
109+
func (impl EnvironmentServiceImpl) GetDataSourceName(environment string) (DataSourceMetaData, error) {
110+
datasource := DataSourceMetaData{}
110111
model, err := impl.environmentRepository.FindOne(environment)
111112
if err != nil {
112113
impl.logger.Errorw("error in fetching environment", "err", err)
113-
return "", err
114+
return datasource, err
114115
}
115116
if model.GrafanaDatasourceId == 0 {
116-
return "", fmt.Errorf("prometheus endpoint not found")
117+
return datasource, fmt.Errorf("prometheus endpoint not found")
117118
} else {
118119
impl.logger.Debugw("environment datasource name", "datasource", model.GrafanaDatasourceId)
119-
datasource, err := impl.grafanaClient.GetDatasource(model.GrafanaDatasourceId)
120+
data, err := impl.grafanaClient.GetDatasource(model.GrafanaDatasourceId)
120121
if err != nil {
121122
impl.logger.Errorw("error in fetching datasource", "err", err)
122-
return "", err
123+
return datasource, err
123124
}
124-
return datasource.Name, nil
125+
datasource.Name = data.Name
126+
datasource.Id = model.GrafanaDatasourceId
127+
return datasource, nil
125128
}
126129
}
127130

131+
type DataSourceMetaData struct {
132+
Id int
133+
Name string
134+
}
135+
128136
func (impl EnvironmentServiceImpl) Create(mappings *bean2.EnvironmentBean, userId int32) (*bean2.EnvironmentBean, error) {
129137
existingEnvs, err := impl.environmentRepository.FindByClusterId(mappings.ClusterId)
130138
if err != nil && !util.IsErrNoRows(err) {

0 commit comments

Comments
 (0)