Skip to content

Elastic search report gets broken if the elastic search server is offline during the first init of the report #1

@maxcherednik

Description

@maxcherednik

The elastic search report is getting the version of the elastic search server during the construction:

public ElasticSearchReport(ElasticReportsConfig reportConfig)
        {
            var uri = new Uri($"http://{reportConfig.Host}:{reportConfig.Port}/_bulk");
            var nodeInfoUri = new Uri($"http://{reportConfig.Host}:{reportConfig.Port}");

            _reportConfig = reportConfig;
            this.elasticSearchUri = uri;

            using (var client = new WebClient())
            {
                try
                {
                    var json = client.DownloadString(nodeInfoUri);
                    var deserializer = new DataContractJsonSerializer(typeof(ElasticSearchNodeInfo));
                    using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json)))
                    {
                        var nodeInfo = (ElasticSearchNodeInfo)deserializer.ReadObject(stream);
                        replaceDotsOnFieldNames = nodeInfo.MajorVersionNumber >= 2;
                    }

                }
                catch (Exception ex)
                {
                    log.WarnException("Unable to get ElasticSearch version. Field names with dots won't be replaced.", ex);
                    replaceDotsOnFieldNames = false;
                }
            }
        }

So in case of any exception here all the following report attempts are broken.

Possible solutions:

  1. Have the version of the elastic search configurable
  2. Make the init lazy by moving to the actual reporting reporting and keep trying to init until it's initialized with every report attempt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions